May be I need to clear some things for you to understand what I really need.
For example: we have a function, that writes on the screen some messages. I can call it like: printf("Hello world %s%s%s%d",s,s,s,d); so on. So - how is it possible for this function get to know the quantity of parameters passed to it, their size and their length? May be it uses some kind of another calling convention, but I do not know where to begin... I did see the disassembled version of printf C/C++ function, but there are nothing special in it :(.
Posted on 2001-08-14 18:02:11 by Maestro

in your disasm of the c/c++ call to printf, you should have noticed that, after the call, there's a ADD ESP, ?. its the c calling style(w32 use pascal style)

this happen coz printf() dont have how know the number of parameters it will be called, so, the caller is responsible for cleaning the stack.

but, when it get the first parameter, the string, and parse it, and count 4 %, it know that it have 4 valid values in stack to work with... the number and the type...

as i said: magic :tongue:

Posted on 2001-08-14 18:12:07 by ancev
At last I got how to manage this. Thanks greatly to ANCEV!
Posted on 2001-08-14 18:39:06 by Maestro

The C function prototype for printf is

int printf(const char *, ...);

C does not know exactly how many parameters pushed into stack. When you see the last parameter in the printf function, it is .... That means printf can have variable arguments. printf function uses va_start et al to find the exact address/value of the parameters passed to the function. printf will get value of parameter from stack for each and every '%' sign encountered in the format string. Regarding the size, it will see again the format. For example %d means 4-bytes, %f means 8-bytes and so on.

You can see an example in asm here. Look at MessageBoxPrintf function.

Hope this helps you.

I forgot to tell which program contains the MessageBoxPrintf function. It is in ScrnSize.asm file.
Posted on 2001-08-15 00:09:59 by sjhenry
Thanks one more time. :)
Posted on 2001-08-15 13:14:14 by Maestro