I have a problem with one thing in assembly. I create a variable
points db 65
. The starting value is 65, but when I want to show this value in program using
invoke CreateWindowEx,0,ADDR classStatic,ADDR points, WS_CHILD or WS_VISIBLE,100,100,50,50,hWnd,0,hInstance,0
it returns ASCII. In this example, the character "A". How do I fix it to show "65"?
The
CreateWindowEx
function is expecting a C-style string, which is a pointer to a NUL-terminated sequence of characters.What you have passed it is actually invalid input, and I'm rather surprised that you got "A" instead of "A$^a!bunch?*of-@(nasty^&+garbage{%". You got lucky that a 0 was placed after your
points
constant, probably because of padding inserted by the assembler.If you want to display a number as the caption of your window, then you will first need to convert that number into a string. There are various ways of doing this. The simplest is just to call a function that will do it for you. Since you're already linking to the Win32 API, you can get away with calling
wsprintf
. Better yet, link to a C runtime library and callsnprintf
. Alternatively, you can write your own code that converts a number to a string.Assuming that your string is static, an even better approach would be to simply use a string in the first place:
(might want to pick a better name than
points
).Also note that Windows is a Unicode-based operating system, and it implements Unicode via a 2-byte UTF-16 type. Therefore, you should always explicitly call the
W
-suffixed versions of Windows API functions (or define theUNICODE
and_UNICODE
symbols), and your string characters will need to be WORD-sized. Therefore, the code would be: