How can I declare a function that takes a variable parameter
I have this but it doesn't work :(

Send proc C lpData:DWORD, lpArray:VARARG
LOCAL szBuffer[256]:BYTE

invoke wsprintf, addr szBuffer, lpData, lpArray
; code
Send endp

It gives me the following error:
error A2114: INVOKE argument type mismatch : argument : 0

Posted on 2003-11-21 01:18:37 by Rammstein
You wrong use wsprintf. Need use wvsprintf. Try it

szHi db 'Hi', 0
szFmt db '%d %s',0


Send proc C lpFormat:LPSTR, lpArg1:VARARG
LOCAL szBuffer[1024]:BYTE

invoke wvsprintf, addr szBuffer, lpFormat, addr lpArg1
invoke MessageBox, NULL, addr szBuffer, offset szHi, MB_OK
Send endp

main proc
invoke Send, addr szFmt, 0, offset szHi
invoke ExitProcess, 0
main endp
end main
Posted on 2003-11-21 04:10:17 by P2M

The problem with his code is not about wsprintf. The main problem lies in "VARARG". And also if I am not wrong, lpformat and lparg1 are both pointers, and thus no need for "addr".

wsprintf makes use of C calling convention. If the number of parameters is not known (ie you are using VARARG), the compiler cannot determine how much of the stack to be cleared up. Therefore the compiler generate errors.
Posted on 2003-11-21 05:55:13 by roticv
Insofar I have understood Rammstein wants something like

void Send(const char *format, ...)
char buffer [256];

wvsprintf(buffer, format, (char *)(&format) + sizeof(format));

// code
Posted on 2003-11-23 19:10:33 by P2M
Now I see the difference between wvsprintf and wsprintf. Just realised that var_list is a dword and the function uses stdcall convention.
Posted on 2003-11-24 04:51:20 by roticv