如何让VC调用Delphi生成的DLL?(200分)

J

juxd

Unregistered / Unconfirmed
GUEST, unregistred user!
VC调用VC生成的DLL,Delphi调用Delphi生成的DLL以及Delphi调用VC
生成的DLL都容易实现,但如何让VC调用Delphi生成的DLL不明白的说
(那个同名的lib是否需要,如需要应该怎样得到?),请大虾出手,
举个简单的例子。
 
必须声明__stdcall的形式,而且在VC中只能动态调用DLL中的函数。也就是说
必须用LoadLibrary和GetProcAddress函数来取Dll中的函数。Delphi中的
Lib在VC中不能用只需Delphi的.Dll文件就可以了。
 
补充一点在Delphi的Dll不能写成类的形式,在VC中调用dll的文件也必须设为
__stdcall的调用方式。
 
谢谢Fencer指点,我用的就是__stdcall,请举个最简单的例子。
如Delphi的DLL为MakeDll.dll:
library MakeDll;
uses
SysUtils, Classes;
function MyFunc(Add1, Add2: Integer): Integer;
stdcall;
begin
Result:= Add1 + Add2;
end;

exports
MyFunc;
begin
end.

怎样在VC中调用MyFunc?
 
问题已经解决,是这样的,供参考
在*.h中
...
typedef long (CALLBACK* LPDLLMYFUNC)(long, long);
...
在*.cpp中
...
long marker = 0;
HINSTANCE hInst = NULL;
LPDLLMYFUNC lpDllMyFunc;
hInst = AfxLoadLibrary("MakeDll.dll");
if (hInst != NULL)
{
lpDllMyFunc = (LPDLLMYFUNC)GetProcAddress(hInst, "MyFunc");
if (lpDllMyFunc)
marker = lpDllMyFunc(12, 34);
AfxFreeLibrary(hInst);
}
... //if all OK, the marker is 46

谢谢Fencer的重要提示,并给分。
 
顶部