News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

alias for proc statement, calling assembly from C

Started by skippyV, April 19, 2011, 02:58:04 PM

Previous topic - Next topic

skippyV

Trying to determine if I can associate a proc definition with a prototype BUT have the proc take no args while the proto takes several.
For example, I use IDA Pro to grab a disassembly of a function.  It's obvious how many parameters it takes but I don't want
to have to dummy up those parameters to make it link. Besides - the "dummy" parameters generate warnings.
IDA will produce disassembly like:
sub_2F539A  proc  near
  arg_0 = dword ptr 8
  arg_4 = dword ptr 0Ch
  arg_8 = word ptr  10h
  push   ebp,
  mov   ebp, esp

Since the prologue and epilogue is already there I just put in:
OPTION PROLOGUE:none
OPTION EPILOGUE:none

On the C side, to call this routine, I have to prototype it like:
int __stdcall sub_2F978(int*, int*, short*);
And on the masm side I have to tweak the proc statement:
sub_2F978 proc near STDCALL  arg0:DWORD, arg4:DWORD, arg8:DWORD
Which generates the warnings for unused variables declared in the proc statement - as expected.
So what I'd like to do is:
   - remove the warnings without tweaking the function contents
   - since I know how many parms is needed, use some sort of macro or typedef that
     when combined with the proc statement would satisfy the linker.
Something like:
parms3 TEXTEQU :DWORD, :DWORD, :DWORD
  sub_2F539A  proc  near  parms3

That way I could have several macros handy. One for each number of input args.

Regards,

qWord

what about this:
Quoteparams macro n:req
   params_txt TEXTEQU <STDCALL>
   params_cntr = 0
   WHILE params_cntr LT n
      params_txt CATSTR params_txt,@SubStr(< ,>,((params_cntr NE 0) AND 1)+1,1),<arg_>,%params_cntr,<:DWORD>
      params_cntr = params_cntr + 1
   ENDM
   EXITM params_txt
endm
...
bla proto params(3)
...
bla proc params(3)
   
   ret
bla endp
FPU in a trice: SmplMath
It's that simple!

skippyV

I think you're on the right track, qWord.

You're macro generated the following error:
Quoteerror A2008:syntax error : STDCALL
fatal error A1010:unmatched block nesting : sub_2F978
I used it with my proc statement as so:
sub_2F978 proc near STDCALL params(3)

The error is similar to those generated when I list parameters without names in the proc statement.

I should mention that I'm using Visual Studio 2008.

qWord

the macro also add 'STDCALL' to the line:
sub_2F978 proc params(3)This should work. It is the same as writing:
sub_2F978 proc SDTCALL arg_0:DWORD,arg_1:DWORD,arg_2:DWORD

BTW: the NEAR-keyword ist not needed
FPU in a trice: SmplMath
It's that simple!

skippyV

Thanks, qWord  :U
I should have read your macro more carefully.

It will certainly shave off some of my time.