|
Matt Newman wrote:
convert a CString to char
I think you actually want a const char*. Anyway, you should be able to just pass the CString object right in because it has a default LPCTSTR operator.
|
|
|
|
|
Matt Gullett wrote:
I think you actually want a const char*.
I double checked and that is the one I want. However when I try to compile
CString strDest = _T("192.168.0.6");
...
dwForwardDest = inet_addr(strDest);
I get this compile error:
error C2664: 'inet_addr' : cannot convert parameter 1 from 'CString' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
- Matt Newman / Windows XP Activist
"Well, the guy that's giving you a hard time is a f***in moron, and you can tell him thats straight from another Linux user." - John Simmons on Linux Users Just do the American thing and shoot him... - Jim Crafton on Linux Users Wh3n my l33t skillz 1mpr0v3, I w1ll h4ck M$, 4nd th3n wh0 w1ll b3 l4ugh1ng ? N0t Bill. H4 h4 h4 h4 h4 h4 h4. - Christian Graus
|
|
|
|
|
CString strDest = _T("192.168.0.6");
char buff[512];
_tcscopy(buff,strDest);
dwForwardDest = inet_addr(buff);
Thats what I'd do, and I've used it on a couple of oldie winsock programs so it seems to work for me.
|
|
|
|
|
I tried this but I got an error
error C2664: 'wcscpy' : cannot convert parameter 1 from 'char [512]' to 'wchar_t *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
- Matt Newman / Windows XP Activist
"Well, the guy that's giving you a hard time is a f***in moron, and you can tell him thats straight from another Linux user." - John Simmons on Linux Users Just do the American thing and shoot him... - Jim Crafton on Linux Users Wh3n my l33t skillz 1mpr0v3, I w1ll h4ck M$, 4nd th3n wh0 w1ll b3 l4ugh1ng ? N0t Bill. H4 h4 h4 h4 h4 h4 h4. - Christian Graus
|
|
|
|
|
Is this a UNICODE build? Are you building under VC7?
I am not 100% sure, but on VC7 you may need to do (LPCTSTR)strSomeString to get what you want.
If this is a UNICODE build, you will need to convert the contents of the CString from UNICODE WCHAR to char. Take a look at the wctomb function.
|
|
|
|
|
I forgot about the UNICODE troubles but the (LPCTSTR) trick doesn't seem to work for this one.
- Matt Newman / Windows XP Activist
"Well, the guy that's giving you a hard time is a f***in moron, and you can tell him thats straight from another Linux user." - John Simmons on Linux Users Just do the American thing and shoot him... - Jim Crafton on Linux Users Wh3n my l33t skillz 1mpr0v3, I w1ll h4ck M$, 4nd th3n wh0 w1ll b3 l4ugh1ng ? N0t Bill. H4 h4 h4 h4 h4 h4 h4. - Christian Graus
|
|
|
|
|
I am able to use a standard CString, strange that its giving you an error.. Maybe try
dwForwardDest = inet_addr(LPCTSTR("192.168.0.6"));
|
|
|
|
|
It is giving me errors because I am converting a MBCS console application to a UNICODE MFC appplication so the UNICODE/MBCS types are conflicting etc
- Matt Newman / Windows XP Activist
"Well, the guy that's giving you a hard time is a f***in moron, and you can tell him thats straight from another Linux user." - John Simmons on Linux Users Just do the American thing and shoot him... - Jim Crafton on Linux Users Wh3n my l33t skillz 1mpr0v3, I w1ll h4ck M$, 4nd th3n wh0 w1ll b3 l4ugh1ng ? N0t Bill. H4 h4 h4 h4 h4 h4 h4. - Christian Graus
|
|
|
|
|
Matt Newman wrote:
cannot convert parameter 1 from 'CString' to 'const char *'
That tells me you're doing a Unicode build. CString has an LPCTSTR converter, which is a Unicode string in Unicode builds. Since you need a single-byte string, you'll need to convert it. The quickest way is an ATL conversion macro.
#include <atlconv.h>
{
USES_CONVERSION;
CString strDest = _T("192.168.0.6");
...
dwForwardDest = inet_addr( T2CA((LPCTSTR)strDest) );
}
--Mike--
When 900 years old you reach, look as good you will not. Hmm.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Michael Dunn wrote:
T2CA
DOH! I with I knew about this several months ago. I know how to do it manually, but this is much, much easier.
|
|
|
|
|
I tell you all higher education does is makes you for get the UNICODE/MBCS conversion macros Thanks for the help!
- Matt Newman / Windows XP Activist
"Well, the guy that's giving you a hard time is a f***in moron, and you can tell him thats straight from another Linux user." - John Simmons on Linux Users Just do the American thing and shoot him... - Jim Crafton on Linux Users Wh3n my l33t skillz 1mpr0v3, I w1ll h4ck M$, 4nd th3n wh0 w1ll b3 l4ugh1ng ? N0t Bill. H4 h4 h4 h4 h4 h4 h4. - Christian Graus
|
|
|
|
|
thanks a lot !
|
|
|
|
|
hi
is there any simple way to load images such as BMP or Gif or any other formats from Resources and NOT FROM THE FILE using GDI+ .
for example i include a bitmap in Resource .how can i Load it in my project that project.EXE don't need that picture file anymore.
regards
|
|
|
|
|
Bitmap::FromResource()
--Mike--
When 900 years old you reach, look as good you will not. Hmm.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
i use this code line but it's not work . what is wrong with me?
<br />
Graphics graphics(dc.m_hDC);<br />
<br />
graphics.DrawImage(Bitmap::FromResource(AfxGetInstanceHandle(), L"IDB_BITMAP1"),0,0,400,400);
|
|
|
|
|
Use passing the string "IDB_BITMAP1" instead of the numeric value of IDB_BITMAP1.
Bitmap::FromResource ( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1) )
--Mike--
When 900 years old you reach, look as good you will not. Hmm.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
i did my best but this error occures again :
cannot convert parameter 2 from LPSTR to Const WCHAR *
how can i fix this
|
|
|
|
|
Your problem has to do with the fact that GDI+ uses all wide character strings (UNICODE) so you have to convert all strings passed to GDI+ functions to wide characters.
#include <afxpriv.h>
...
USES_CONVERSION;
Bitmap::FromResource ( AfxGetResourceHandle (), T2W ( MAKEINTRESOURCE (IDB_BITMAP1) ) );
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
Actually, that's not correct in this case. MAKEINTRESOURCE just expands to a cast, it doesn't create an actual string. So that code will probably crash or give incorrect results when something that isn't a string is passed to T2W .
--Mike--
When 900 years old you reach, look as good you will not. Hmm.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Bitmap::FromResource ( AfxGetInstanceHandle(), (LPCWSTR) MAKEINTRESOURCE(IDB_BITMAP1) )
The cast to (LPCWSTR) is the correct way in this case due to the way the APIs handle resource IDs. All resource ID parameters are strings, usually LPCTSTR , because a resource ID can be either a real string or a number. When you pass a numeric ID, you use the MAKEINTRESOURCE macro to convert it to a string - the macro just expands into a cast to LPCTSTR .
The problem with GDI+ is that its functions take LPCWSTR parameters. Since I assume you're doing an ANSI build, MAKEINTRESOURCE casts to LPCSTR , not LPCWSTR . Since you are passing a number, not a real string, you need to cast to LPCWSTR to satify the compiler. The API will know what to do with the value.
[edit]
Actually, never mind all that (but it's still good to know the technicalities of resource IDs ). Use the MAKEINTRESOURCEW() macro which always casts to LPCWSTR .
[/edit]
--Mike--
When 900 years old you reach, look as good you will not. Hmm.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
thats Workkkkkk i can't believe itttttt
Thanksss A LOOOTTTTT
|
|
|
|
|
Hi,
I am developing a program that needs to read a text file to the user. Could anybody tell me where I can find such a open source program or API? Thanks
|
|
|
|
|
Use the Speech SDK.
A tutorial on it can be found at:
http://www.ltpb.8m.com/tutorial/Listall.html[^] (i forgot the direct url, but this is the list)
-Steven
CP.Lounge.Addicts+="Steven";
By reading this message you are held fully responsible for any of the mispelln's or grammer, issues, found on, codeproject.com.
For those who were wondering, actual (Linux) Penguins were harmed in creating this message.
|
|
|
|
|
I'm having trouble linking to a DLL that I've made. I have a project that uses multiple DLLs that we've created in house. Everything uses this one DLL that's has the most commonly used classes. Amazingly enough it's called common.dll. Anyway I'm having trouble linking to it in one of the other dlls. The signature that it gives in the error is ?StartServiceA@CTcpClient@@UAEHXZ. BUT the signature in the mapfile of common.dll and according to dependency walker is ?StartService@CTcpClient@@UAEHXZ. Common.dll as well as the CTcpClient class inside of it is used in many other things. They all link fine. One other note of interest. This linking error only happens when CTcpClient is created dynamically. If I create it using CTcpClient newClient(blah,blah,blah) all works. Thanks for the help.
Here's the full linking error.
Linking...
Creating library ..\..\..\lib/NetTraffic.lib and object ..\..\..\lib/NetTraffic.exp
ClientInterface.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall CTcpClient::StartServiceA(void)" (?StartServiceA@CTcpClient@@UAEHXZ)
..\..\..\lib/NetTraffic.dll : fatal error LNK1120: 1 unresolved externals
nay
|
|
|
|
|
A few questions to the wise:
1) If I call strdup for a pointer to a string which is a member of class do I need to call free before recalling?
eg. cMyClass.szString = strdup(szString1);
cMyClass.szString = strdup(szString2);
Does the above cause a memory leak if I don't use free(cMyClass.szString); before the second call to strdup?
2) In a similar case if I am using strdup but there are pointer to class as in a linked list and I use delete to delete the pointer does that also free the memory taken up by strdup or I would have to free that memory first and then call delete on the pointer?
|
|
|
|