How to convert C++ header file to delphi -
i'm converting c++ header delphi pas file. first, converted c++ header using headconv 4.0 dr.bob module. failed compiling. can converting?
****** c++ header ******
#if !defined(____kkk_module__) #define ____kkk_module__ #ifdef kkk_module_exports #define kkk_module_api extern "c" __declspec(dllexport) #else #define kkk_module_api extern "c" __declspec(dllimport) #endif kkk_module_api int _stdcall kkk_creat(); ......
above code converted delphi code leads error below;
****** delphi code ******
{$ifdef kkk_module_exports} const kkk_module_api = extern 'c' __declspec(dllexport); **//error** {$else} const kkk_module_api = extern 'c' __declspec(dllimport); **//error** {$endif} var kkk_creat: function: kkk_module_api int cdecl {$ifdef win32} stdcall {$endif}; .........
cause of error 'extern' not reserved syntex of delphi. don't know how replace delphi code , need help.
that not c#, c++.
the conditional section common pattern allow header file used both when building library , when importing it. importing don't need translate part.
you left single function:
extern "c" __declspec(dllimport) int _stdcall kkk_creat();
the use of extern "c"
suppresses c++ name mangling. don't translate that.
loosely, translate __declspec(dllimport)
external
directive.
translate to:
function kkk_creat: integer; stdcall; external libname;
where libname
string containing name of dll.
you need check name used export function. if library built without .def file function names decorated. function named kkk_creat@0
. use tool dumpbin or dependency viewer check exported function names in dll.
fwiw, i've never found effective general purpose header translator , have found best manually, or write bespoke header specific translator.
Comments
Post a Comment