I'm atempting to write a procedure that gets a variable number of parameters For simplicity, the 2nd param is always a param count (and the first is always used).

According to the Programmer's Guide (chap 7 and 12), I can declare a proc to be vararg if I'm using stdcall.

I'm doing exactly that, and still I get the error:

"VARARG parameter requires C calling convention"

Anyone have a clue how to eliminate this?

TIA
Posted on 2001-12-29 00:29:24 by Ernie
STDCALL has the proc cleaning up the stack, which I see as more
or less impossible with vararg... but you can have your main app
run stdcall and do "C" override on the procs that need vararg.



MyFunkyProc PROTO C :VARARG


--- something like that.
Posted on 2001-12-29 00:45:43 by f0dder
invokeC macro funk:REQ,vars:VARARG

LOCAL ivars
ivars=0
FOR var, <vars>
ivars=ivars+4
ENDM

invoke funk,vars
add esp,ivars
ENDM
Posted on 2001-12-29 01:26:59 by bitRAKE
What is this Programmer's Guide ?

And Oh! Donuts Ernie!, When I lived in San Bernardina CA
there were lot's of Donut Stores,
I sure love an Orange Cake Donut!

Andy
Posted on 2001-12-29 08:37:44 by andy981
I was trying to avoid say so, but this is for a general purpose (reuseable) event source handler. It is the part that actually fires the event. Events are a type of callback, they may have any number of parameters, and I would prefer a single routine to handle them all.

(I'm not gonna say C*M, cause if I d Hiro's gonna toss this thread there, but it's an ASM question, not a C*M question)

Calling this proc is not the problem, a simple macro can do that:



;-------------------------------------------------------------------------------
FireEvents MACRO pInterface:REQ, args:VARARG
LOCAL istatement, argCount
argCount = 2 ; always pass THIS, and always include a parameter count
FOR arg, <args> ;; run thru args to see if edx is lurking in there
argCount = argCount + 1
IFIDNI <&arg>, <edx>
.ERR <edx is not allowed as a FireEvent parameter>
ENDIF
ENDM
IFIDNI <&pInterface>, <edx>
.ERR <edx is not allowed as a FireEvent parameter>
ENDIF
istatement CATSTR <invoke (comethod>, %argCount, \
< PTR [edx + ICPManager.ICPManager_FireEvent]), pInterface, >, \
%argCount
IFNB <args> ;; add the list of parameter arguments if any
istatement CATSTR istatement, <, >, <&args>
ENDIF
mov edx, pInterface
mov edx, [edx]
istatement
ENDM
;-------------------------------------------------------------------------------


I even get a param count check in the invoke inside that, as comethodX is a series of procedure pointers, where X is the parameter count. It generates the following code:



FireEvents this_, Param1, Param2, ... ParamN
mov edx, this_
mov edx, [edx]
push ParamN
...
push Param2
push Param1
push +000000005h
push this_
call dword ptr [edx]+000000020h


So I get a proper stack frame. I'm just worried how I handle it in the ICPManager_FireEvent procedure. Since I could not get stdcall to work, I made this proto to only have 2 parameters, the THIS and the ParamCount, as it will ALWAYS have these.

I believe if I just subtract 4 * (param count - 2) from the stack pointer, I will clean up any 'extra' items on the stact, and the usuale 'ret' will clean up the always there last two.

This would seem to work, but it doesn't seem 'elegant,' it seems a cluge.

Any other suggestions?
Posted on 2001-12-29 08:43:45 by Ernie
The MASM Programmers Guide is a 454 page softbound manual that describes how to use MASM. It was published my Microsoft in the days when MASM was a seperate product and could be purchased.

That's how I got my orgional copy. I bought it.

I have seen the manuals online in electronic format. While the legality of publishing this material is in doubt, it is the only way to obtain it now.

If someone knows a valid link perhaps they would be kind enough to post it here. Hiro can delete it if he disagrees (and we'll just have to email the link directly outside of the board).
Posted on 2001-12-29 08:49:28 by Ernie

If someone knows a valid link perhaps they would be kind enough to post it here. Hiro can delete it if he disagrees (and we'll just have to email the link directly outside of the board).


http://www.crackpl.site.pl/a_documents/masm61.zip (~2.29 MB, 493 page PDF)
Posted on 2001-12-29 08:57:10 by bazik
Thanks !
Posted on 2001-12-29 10:07:39 by andy981