LPTSTR type
-
I'm programing in C language. I'd like to use the wsprintf function with a LPTSTR variable. here my code: void GetDescription (LPTSTR Description) { char TypeRes[100]; char Resources[100]; lstrcpy (TypeRes, "Bitmap"); lstrcpy (Resource, "file.bmp"); Description=wsprintf (Description, "<%s : %s>", TypeRes, Resources); } It doesn't work! The variable Description is empty or invalid. But I have to use LPTSTR not char[xxx], otherwise, my program is very slow and I get a memory error. Help me!!!!!!:confused: Appstmd
-
I'm programing in C language. I'd like to use the wsprintf function with a LPTSTR variable. here my code: void GetDescription (LPTSTR Description) { char TypeRes[100]; char Resources[100]; lstrcpy (TypeRes, "Bitmap"); lstrcpy (Resource, "file.bmp"); Description=wsprintf (Description, "<%s : %s>", TypeRes, Resources); } It doesn't work! The variable Description is empty or invalid. But I have to use LPTSTR not char[xxx], otherwise, my program is very slow and I get a memory error. Help me!!!!!!:confused: Appstmd
If you use wsprintf() I guess you have defined UNICODE and _UNICODE, in that case you can not ude char, but should instead use wchar_t. Description=wsprintf() fails, wsprintf returns the number of characters the function put in to a string, not the string itself, so you should use something like int result = wsprintf (Description, "<%s : %s>", TypeRes, Resources);. Make sure that Description are large enough to contain the text you pun into it with wsprintf() - Anders Money talks, but all mine ever says is "Goodbye!"
-
If you use wsprintf() I guess you have defined UNICODE and _UNICODE, in that case you can not ude char, but should instead use wchar_t. Description=wsprintf() fails, wsprintf returns the number of characters the function put in to a string, not the string itself, so you should use something like int result = wsprintf (Description, "<%s : %s>", TypeRes, Resources);. Make sure that Description are large enough to contain the text you pun into it with wsprintf() - Anders Money talks, but all mine ever says is "Goodbye!"
If you use wsprintf() I guess you have defined UNICODE and _UNICODE, in that case you can not ude char, but should instead use wchar_t. This is not correct. The function has ANSI and UNICODE versions. In this case, the w does not refer to a wide character variant. It refers to a windoze-specific function that resides in user32.dll and is not part of the C runtime library.
-
If you use wsprintf() I guess you have defined UNICODE and _UNICODE, in that case you can not ude char, but should instead use wchar_t. This is not correct. The function has ANSI and UNICODE versions. In this case, the w does not refer to a wide character variant. It refers to a windoze-specific function that resides in user32.dll and is not part of the C runtime library.
Oops :-O - Anders Money talks, but all mine ever says is "Goodbye!"
-
I'm programing in C language. I'd like to use the wsprintf function with a LPTSTR variable. here my code: void GetDescription (LPTSTR Description) { char TypeRes[100]; char Resources[100]; lstrcpy (TypeRes, "Bitmap"); lstrcpy (Resource, "file.bmp"); Description=wsprintf (Description, "<%s : %s>", TypeRes, Resources); } It doesn't work! The variable Description is empty or invalid. But I have to use LPTSTR not char[xxx], otherwise, my program is very slow and I get a memory error. Help me!!!!!!:confused: Appstmd
You should:
- use the
TEXT()
or_T()
macros for all your string literals - use
TCHAR
instead ofchar
- include
tchar.h
- and if you have
UNICODE
and_UNICODE
defined (ie you are using unicode version ofwsprintf
), make sure you check the "Display unicode strings" options under the Debug tab of the VC++'s Options dialog.
PS. Are you sure you have a valid buffer in
Description
? PPS. Just saw you assigningDescription
from the results ofwsprintf
. Did you read the docs at all?LPTSTR
is not a string class :mad:! You are making theDescription
pointer to point to some invalid address after the function call. - use the
-
Oops :-O - Anders Money talks, but all mine ever says is "Goodbye!"
-
I'm programing in C language. I'd like to use the wsprintf function with a LPTSTR variable. here my code: void GetDescription (LPTSTR Description) { char TypeRes[100]; char Resources[100]; lstrcpy (TypeRes, "Bitmap"); lstrcpy (Resource, "file.bmp"); Description=wsprintf (Description, "<%s : %s>", TypeRes, Resources); } It doesn't work! The variable Description is empty or invalid. But I have to use LPTSTR not char[xxx], otherwise, my program is very slow and I get a memory error. Help me!!!!!!:confused: Appstmd
Assuming the calling code is passing a valid buffer in the Description parameter, take out the "Description =" part and it will work. Then do all the TCHAR-related stuff the other posts have mentioned (although they are wrong about Unicode; wsprintf() is not a Unicode-only function, that would be swprintf()). --Mike-- Fetchez la vache! My really out-of-date homepage Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan and Jamie Salé.
-
Oops :-O - Anders Money talks, but all mine ever says is "Goodbye!"
Thks a lot! The code now works perfectly. My variable Description was not large enough:-O ... Here the changes: Lenght=lstrlen(TypeRes)+lstrlen(Resource); Description = (char*) malloc(Lenght); Description[Lenght]='\0'; wsprintf (Description, "<%s : %s>", TypeRes, Resource); Appstmd
-
Thks a lot! The code now works perfectly. My variable Description was not large enough:-O ... Here the changes: Lenght=lstrlen(TypeRes)+lstrlen(Resource); Description = (char*) malloc(Lenght); Description[Lenght]='\0'; wsprintf (Description, "<%s : %s>", TypeRes, Resource); Appstmd
The code is still wrong, you don't allocate enough space for the Description string. Look at the wsprintf() format - you have the two substrings, two angle brackets, two spaces, and a colon. Plus the terminating null. So you should malloc
(lstrlen(TypeRes) + lstrlen(Resource) + 6)*sizeof(TCHAR)
--Mike-- Fetchez la vache! My really out-of-date homepage Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan and Jamie Salé.