Archived

This topic is now archived and is closed to further replies.

phueppl1

using .lib between C++ and Delphi

Recommended Posts

phueppl1    122
Hi! I''m trying to write an API for a Server system and I want to compile it to a statical linked lib. How can I make sure that this library can be used in Delphi and in C/C++ ? the API is GL like -> almost standard C.. ok, thx, cya, Phil Visit Rarebyte! and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states )

Share this post


Link to post
Share on other sites
Michalson    1657
Assuming your talking about dll files then your concern will be 1) datatypes and 2) calling standards (how parameters are passed and who is responsible for the stack).

For datatypes you want to ensure the datatype is know by both languages (Delphi "String" is unknown to C, but C "float" is just a Delphi "Single"). You also want your structs, etc to be designed so that both compilers look for the fields at the same offsets in memory. In Delphi you can achive this by using the packed keyword to prevent it from padding record (and object) structures, in C you can turn it off.

For passing you want to make sure they both pass parameters in the same manner. IMO the easiest way to do this is to define all your exported functions (in a delphi dll) and your imported functions (in a delphi exe) use the cdecl passing method, this is the same as C''s standard.

function MyFunction(Parameter:Integer):Integer;cdecl;

You could also use stdcall, which is what all the windows api libraries use (just lookup how to link api functions in C)

Share this post


Link to post
Share on other sites
phueppl1    122
Ok thx alot! Now I know that for a .dll
but is there a way to use a statical .lib file ? I don''t want to use dlls because a) I don''t want to load the function pointers manually b) I want to use global variables (it''s going to be a state machine, like GL) in the .lib file, so I don''t want the dll to be loaded multiple times.

if not, I guess I''ll have to stick to the .dll and watch out that it isn''t loaded twice :|

cya,
Phil

Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states )

Share this post


Link to post
Share on other sites
Michalson    1657
I''m not sure about C/C++, but if your writing in Delphi lookup the ShareMem library, it lets you share blocks of memory between dll''s/programs (even with C++ since the functionality is provided by a free borland DLL)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Delphi can create c/c++ compatible obj files. Perhaps you can uses them to build a lib.

Share this post


Link to post
Share on other sites
phueppl1    122
thx, is there a way for the other way around? creating delphi compatible libs with VC or so?

Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states )

Share this post


Link to post
Share on other sites