flat assembler
Message board for the users of flat assembler.
Index
> Windows > Correct way to convert binary to decimal in windows? |
Author |
|
LocoDelAssembly 04 Oct 2008, 00:04
It is not wrong but you could save yourself from doing the string concatenation by just doing it this way
Code: include "win32ax.inc" PATH_SIZE = 256 .data fmt db "Length: %u", 0 buff rb $ - fmt + 10 windir rb PATH_SIZE .code start: invoke GetWindowsDirectory, windir, PATH_SIZE ; The documentation says that it should be MAX_PATH cinvoke wsprintf, buff, fmt, eax invoke MessageBox, NULL, windir, buff, MB_OK invoke ExitProcess, 0 .end start [edit]It was something wrong, wsprintf must be called with cinvoke or "ccall [wsprintf], ..." |
|||
04 Oct 2008, 00:04 |
|
windwakr 06 Oct 2008, 00:35
What is cinvoke and why does it need to be used instead of invoke?
Does this work on all windows versions 95 and up? Thanks |
|||
06 Oct 2008, 00:35 |
|
LocoDelAssembly 06 Oct 2008, 00:49
Well, you have to read http://flatassembler.net/docs.php?article=win32 , however it is not explained with an example what cinvoke/ccall does so here the same call without macros
Code: push eax push fmt push buff call [wsprintf] add esp, 4*3 ; Here the important part that invoke/stdcall don't have Because wsprintf uses cdecl calling convention instead of stdcall, you need cinvoke. According to MSDN the minimum operating systems are Windows 95 and Windows NT 3.1. BTW, this is not "the way" to convert to decimal, it is just one way but nothing stops you from doing your own routine (like you did it in DOS?). But it is very handy and many times the preferable way. I think it is better to use a function already loaded in memory than wasting more RAM writing your own for few to nothing speed improvement (which if it is used to show something on the display then it is very stupid to optimize for speed rather than for size). PS: I know that importing wsprintf takes more space than a simple IntToStr, but when you need to produce a string with many values in it, the whole code dedicated to that will be bigger than just importing the function. |
|||
06 Oct 2008, 00:49 |
|
revolution 06 Oct 2008, 00:50
wsprintf (wsprintfA & wsprintfW) is the only Win32 API that uses CDECL calling convention so the caller must restore the stack. All other Win32 APIs use STDCALL convention so the stack is restored the the function called.
Last edited by revolution on 06 Oct 2008, 01:22; edited 1 time in total |
|||
06 Oct 2008, 00:50 |
|
windwakr 06 Oct 2008, 01:17
Ok, thanks for explaining that to me.
|
|||
06 Oct 2008, 01:17 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.