I appreciated Henry's comment regarding my last question (generating a .lib file from a FPC-generated for linking with VC++). I ended up using implib (http://implib.sourceforge.net) to generate the .def file with dll2def.exe and then fasm.exe to create the .lib file from that, and VC++ seems to link fine against it.
My fight is with calling conventions and exported names. I've read the programmers guide chapters 6, 7, and 12, and got a lot of useful information out if it. I'm trying now to get a grasp of how different calling conventions work, what different compilers generate what name decorations with the different calling conventions, what compilers require when linking against them, etc.
I've got a little test library with two functions:
function stdcallSquare(value : cint) : cint; stdcall;
function cdeclSquare(value : cint) : cint; cdecl;And I'm trying to use them in a Visual C++ project. In my .cpp file, I have:
extern "C" {
int __declspec(dllimport) __cdecl cdeclSquare(int value);
int __declspec(dllimport) __stdcall stdcallSquare(int value);
}In the "exports" section of my FPC library, I can simply export cdeclSquare without modifying the name it's exported as, and VC++ finds and links against and calls it just great.
If I try to export sdtcallSquare without modifying the name it's exported as, VC++ complains with "1>testdll.obj : error LNK2019: unresolved external symbol referenced in
function _wmain".
If I put "stdcallSquare name ''" in my exports section, then VC++ seems to be happy with it and it links and calls the routine Ok.
So my question is, is there a way to have FPC automatically generate the decoration VC++ is looking for? Or does anyone know of a way to make VC++ find and link stdcall functions without the decorations?
I know I could just use cdecl and forget about stdcall altogether, but I'd like to learn how to do it with stdcall but I'm just curious to see if there's a way to get stdcall to work without having to manually put the decorations on the exported names myself.
Thanks,
-SG
