Board index » cppbuilder » Calling Pascal and C dll from the same application
Renald Yazmir
CBuilder Developer |
Calling Pascal and C dll from the same application2006-12-01 10:08:19 PM cppbuilder109 I have C application that calls Pascal dll written in Delphi 4 Here is the function in C application that calls a function in Pascal dynamically: double do_something(void) { double a; typedef double FAR PASCAL (* p)(void); p fun_name; fun_name = (p)GetProcAddress(hLib, "do_something_in_dll"); if(fun_name != NULL) a = (fun_name)(); return a; } I converted Pascal dll into C. In dll I declare export function: extern "C" double __declspec(dllexport) do_something_in_dll(void); In my calling appication I kill "FAR PASCAL " double do_something(void) { double a; typedef double (* p)(void); p fun_name; fun_name = (p)GetProcAddress(hLib, "do_something_in_dll"); if(fun_name != NULL) a = (fun_name)(); return a; } Works fine!!! ---------------------------------------------- My goal now is to be able to use both Pascal and C dlls with the same calling application. Therefore I want to preserve old style calling convention with FAR PASCAL: double do_something(void) { double a; typedef double FAR PASCAL (* p)(void); p fun_name; fun_name = (p)GetProcAddress(hLib, "do_something_in_dll"); if(fun_name != NULL) a = (fun_name)(); return a; } My question is how can I declare a function in the C dll with FAR PASCAL so it can be compatible with "my old style" calling convention. I tried def file. It did not work. Here is what I did in dll: in def: LIBRARY my_new_c_dll EXPORTS do_something_in_dll in c: double FAR PASCAL do_something_in_dll(void) { ..... } in h: double FAR PASCAL do_something_in_dll(void); Thank you. Renald |