Hey guys, I'm sure that this is probably something really stupid, but I've been having trouble.

Ok, I have an English string I load from a resource, using LoadStringW. Whenever I pass that string to another function to name the window, it only shows the first character. After loading the string with LoadStringA, and passing it to a Unicode function that would name the window, it'd work fine. This is madness! (inb4thisissparta)

Here's the three ways I did it, all resulting in the exact same effect (only showing the first letter of the string).


invoke LoadStringW,hInst,100,ADDR DataBuffer,SIZEOF DataBuffer
invoke CreateWindowExW,NULL,ADDR MainClassName,ADDR DataBuffer,
  ...



invoke CreateWindowExW,NULL,ADDR MainClassName,NULL,
  ..
mov hWndMain,eax
invoke LoadStringW,hInst,100,ADDR DataBuffer,SIZEOF DataBuffer
invoke SendMessageW,hWndMain,WM_SETTEXT,NULL,ADDR DataBuffer



invoke CreateWindowExW,NULL,ADDR MainClassName,NULL,
  ..
mov hWndMain,eax
invoke LoadStringW,hInst,100,ADDR DataBuffer,SIZEOF DataBuffer
invoke SetWindowTextW,hWndMain,ADDR DataBuffer


Are all the functions somehow defaulting to the ANSI versions? It's odd, because this is the frame window of my MDI program, and yet all the children don't have the same issue...

If anyone wonders, I'm using the latest version of MASM. Downloaded it like a week ago.
Posted on 2008-11-13 13:54:57 by SuperSwampert67
The W stands for 'wide'.

These strings use 16 bits per character (words).
Depending on the language, every second byte will be zero (except for languages like Chinese that need a lot of character codes).

eg 'H',0, 'E',0, 'L',0, 'L',0, 'O',0, 0,0
as apposed to 'HELLO',0

Use the A version of these api if you want strict Ansi (8 bits per character), assuming you don't intend to support these weird foreign languages.
Posted on 2008-11-13 18:30:22 by Homer
Wide strings are the same as Unicode strings, correct?

I do not want to use the ANSI version for sake of easy translation should I ever have my program translated into other languages, even something like, say, Japanese. I'm sure they have to use Unicode for their kanji, etc.

The issue I'm having here is calling a Wide function, but whenever I try to pass a Unicode string, the string is cut off, and the only reason I can think of is because it's loading the string as ANSI.

db "H",0,"E",0,"L",0,"L",0,"0",0,0,0


ANSI strings are terminated by bytes, and Unicode strings are terminated by words. But when I load the string in Unicode from the resource into a memory buffer, and then pass the memory buffer's offset it to CreateWindowExW to load the string, instead of it terminating at two zero bytes in a row (aka 1 zero word), it terminates at a single zero byte instead.

EDIT: Oh, I hate myself so much. I forgot to fix DefFrameProc and make it Wide version. Thanks for the help Homer. Let this be a lesson that you can't forget about default procs. :)
Attachments:
Posted on 2008-11-13 20:52:13 by SuperSwampert67
Happy to help - and yes, beware of bad prototypes in header files.. don't assume that the headers are absolutely correct, even after all these years people are still discovering bad prototypes in MASM32 and other headers.

Posted on 2008-11-13 23:09:42 by Homer