flat assembler
Message board for the users of flat assembler.

Index > Windows > MessageBoxF implementation

Author
Thread Post new topic Reply to topic
Alessio



Joined: 26 Sep 2003
Posts: 35
Location: Viterbo, Italy
Alessio
Hi,

there's an easy way to convert this small function to fasm ?
Maybe using macros ?

Code:
INT MessageBoxF(HWND hWnd, LPCSTR szFormat, LPCSTR szCaption, UINT uType, ...)
{
        CHAR szBuffer[1024] = { 0 };

  va_list pArgList;

       va_start(pArgList, uType);
  vsnprintf_s(szBuffer, 1024, szFormat, pArgList);
    va_end (pArgList);

      return MessageBox(hWnd, szBuffer, szCaption, uType);
}
    


Thanks.
Post 12 Nov 2008, 12:21
View user's profile Send private message MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
in 32 bits, off my head (might need some fixes):
Code:
cproc MessageBoxF, hWnd, szFormat, szCaption, uType
local szBuffer[1024]:BYTE

lea eax, [uType+4]
stdcall vsnprintf_s, addr szBuffer, 1024, [szFormat], eax
stdcall MessageBox, [hWnd], addr szBuffer, [szCaption], [uType]
ret

endp    
Post 12 Nov 2008, 12:48
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:55; edited 1 time in total
Post 12 Nov 2008, 13:44
View user's profile Send private message Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
windwakr
According to a simple search, something you are not capable of, its "a MessageBox with printf functionality.".
Post 12 Nov 2008, 13:50
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

proc MessageBoxF c, hWnd, szFormat, szCaption, uType


http://en.wikipedia.org/wiki/Printf
Quote:
The class of printf functions (which stands for "print formatted")...
Post 12 Nov 2008, 13:56
View user's profile Send private message Reply with quote
Alessio



Joined: 26 Sep 2003
Posts: 35
Location: Viterbo, Italy
Alessio
I've rewritten in this way

Code:
proc MessageBoxF c,hWnd,szFormat,szCaption,uType

        local szBuffer[1024]:BYTE

        lea eax,[uType+4]
        cinvoke _vsnprintf,addr szBuffer,1024,[szFormat],eax
        invoke MessageBox,[hWnd],addr szBuffer,[szCaption],[uType]
        ret
endp
    


I think that is right to use cinvoke for _vsnprintf and invoke for MessageBox.
There's a way to avoid using _vsnprintf and use macros ?


Last edited by Alessio on 13 Nov 2008, 15:43; edited 1 time in total
Post 12 Nov 2008, 14:19
View user's profile Send private message MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
F stands for "format" as on "formatted output".

_vsnprintf is CCALL? Why, it has fixed number of arguments, and all that stdcall shit... but I really am not sure.
Post 12 Nov 2008, 22:50
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
I've rewritten in this way

It must be "cproc", not stdcall "proc", because it is vararg.

Quote:
I think that is right to use cinvoke for _vsnprintf and invoke for MessageBox.

Not sure, check the C header. You might be right.

Quote:
There's a way to avoid using _vsnprintf and use macros ?

no
Post 13 Nov 2008, 09:02
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Alessio



Joined: 26 Sep 2003
Posts: 35
Location: Viterbo, Italy
Alessio
Quote:

It must be "cproc", not stdcall "proc", because it is vararg.


It is not stdcall proc is

Quote:

proc MessageBoxF c,hWnd,szFormat,szCaption,uType


"c" after MessageBoxF doesn't make difference ?


Last edited by Alessio on 13 Nov 2008, 15:42; edited 1 time in total
Post 13 Nov 2008, 10:46
View user's profile Send private message MSN Messenger Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

"c" after MessageBoxF doesn't make difference ?

According to http://flatassembler.net/docs.php?article=win32 it does. Also the doc has no mentions of "cproc" and after including win32axp.inc fasm keeps saying "illegal instruction"
Post 13 Nov 2008, 13:21
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
My bad, i thought macro name was "cproc". Wasn't it "cproc" at least some time ago?
Post 13 Nov 2008, 15:33
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
vid,

You're right, up to 1.60 (AFAIK, 61-63 hole in my archive) there was cproc macro. match definitely supersede separate procs… Wink
Post 13 Nov 2008, 16:05
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
btw baldr, i think nicer allowed syntax is more MASMy:

Code:
proc Something c arg1,arg2    


So it is clear that "c" is not an argument. If I remember correctly, this was allowed by macro (using some ugly nested macro tricks Razz)
Post 13 Nov 2008, 18:06
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
vid,

Nobody can stop you from adding even more matches to the pile... Wink
Post 13 Nov 2008, 19:06
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Yeah, i liked "cproc" better, anyway.
Post 13 Nov 2008, 22:57
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.