I've managed to include an object file created by masm in a Delphi 6 project. The problem is that I have to use pascal calling convention (.model flat, pascal) and then all API-calls will be screwed up because the parameters are being pushed in the wrong order.
How can I keep the pascal calling convention and still be able to invoke apis normally (I don't want to push the parameters manually)?
How can I keep the pascal calling convention and still be able to invoke apis normally (I don't want to push the parameters manually)?
Delight,
Shouldn't you be able to tell delphi to use the pascal calling convention?. Some procedure prototype option or something? The masm procedure uses the pascal calling convention right?
Shouldn't you be able to tell delphi to use the pascal calling convention?. Some procedure prototype option or something? The masm procedure uses the pascal calling convention right?
You are defining the default calling convention, so if you don't specify a calling convention with the "PROC" or "EXTERN" statements that is the one it'll use.
You can of course mix and match, I believe that wsprinft is a C calling convention function.
Mirno
You can of course mix and match, I believe that wsprinft is a C calling convention function.
Mirno
Delight, this is the exact reason why I made my 'protoize' (.lib -> .inc) generate explicit PROC statements instead of relying on ".model". Unfortunately protoize is in a broken state right now (old source rots etc ;)), but a sample full-style declaration would be:
BeginUpdateResourceA PROTO STDCALL :DWORD, :DWORD
So, you should be able to just add "PASCAL" for the exported funcs.
And really, as far as I remember, delphi does support other calling conventions as well - but it's been quite a while since I used delphi, around v2 or v3 I guess. I did link in some assembly back then, though :)
BeginUpdateResourceA PROTO STDCALL :DWORD, :DWORD
So, you should be able to just add "PASCAL" for the exported funcs.
And really, as far as I remember, delphi does support other calling conventions as well - but it's been quite a while since I used delphi, around v2 or v3 I guess. I did link in some assembly back then, though :)
Why not just specify the calling convention in the PROTOs for the Delphi functions, leave the default as stdcall so that internal and api procs use the more sane calling convention.
DelphiProc PROTO PASCAL :DWORD,:DWORD
DelphiProc PROTO PASCAL :DWORD,:DWORD
delphi uses the register calling convention
eax, edx, ecx and stack
taken from delphi help:
Directive Parameter order Clean-up Passes parameters in registers?
register Left-to-right Routine Yes
pascal Left-to-right Routine No
but you can specify to use the stdcall calling convention to be safe
something like:
procedure Demo(s: string); stdcall; external;
eax, edx, ecx and stack
taken from delphi help:
Directive Parameter order Clean-up Passes parameters in registers?
register Left-to-right Routine Yes
pascal Left-to-right Routine No
but you can specify to use the stdcall calling convention to be safe
something like:
procedure Demo(s: string); stdcall; external;
The problem is that Borland is using a slightly different object format and Delphi will complain about various things when changing the .model directive to stdcall.
Would it be possible to create some sort of macro replacement for invoke that pushes the parameters in reversed order?
Would it be possible to create some sort of macro replacement for invoke that pushes the parameters in reversed order?
I solved the problem using the _call macro created by Four-F:
http://www.asmcommunity.net/board/index.php?topic=14450
Thanks for your help.
http://www.asmcommunity.net/board/index.php?topic=14450
Thanks for your help.
Delight, iirc masm supports generation of the old borland-style format by adding the /omf switch to the commandline, and if not, there should be coff->omf conversion tools around. But oh well, if you got it working the other way, I guess that's fine enough :)