Ryanivanka wrote:
so I wonder if compiler make that call using "fastcall" not
"stdcall",and the registers and stack were wrong. but,as I said before
"stdcall" is used in its ".h". Is that enough to convert a delphi
calling convention to a c++ way? or what I should do to convert
".h",".lib" or".dll"?
In a function call both sides have to agree about the "protocol"
details. It's not enough to add __stdcall to the .h file, you also have
to do it on the Delphi side. For example,
procedure SayHi; stdcall;
begin
ShowMessage("Hi");
end;
This would be declared as void __stdcall SayHi(); in the .h file. If you
miss the stdcall from either side, it won't work. Optionally, you could
use cdecl on both sides, Delphi can handle that. As Cholo said, don't
use fastcall, it's not compatible across compilers.
In addition to making the calling conventions compatible, you also have
to make sure that the argument sizes and alignments match. For example,
Borland's enumerations have the size of 1 byte by default, while in VC++
an enum is treated as an integer (4 bytes). String arguments must be
passed as PChar/char*. Some Delphi floating point types aren't
compatible with VC++ floating point types. Delphi functions are able to
return types not allowed in C/C++ (such as arrays). If you allocate
memory in Delphi, you must delete it from Delphi, too.
I think you should show us your C and Delphi declarations, and we should
be able to compare them for you.
Delphi classes must be flattened into C-style functions before you can
use them from VC++, or they can be wrapped into COM objects.
Tom