1)说明函数类型: Type TVCvoidfunction=Function(......); Cdecl; //函数类型 Type TVCdwordfunction=Function(......); Cdecl; //函数类型 2)定义函数变量: Var VCvoidfunction: TVCvoidfunction; VCdwordfunction: TVCdwordfunction; 3、在Delphi程序中首先动态连接DLL: DLL_Handle:=LoadLibrary(PChar(DLLPath)); DLL_Handle>0 Then //若加载成功, Begin //则依次定位函数 Try @VCvoidfunction :=GetProcAddress(DLL_Handle,'VCvoidfunction'); @VCdwordfunction:=GetProcAddress(DLL_Handle,'VCdwordfunction); Except FreeLibrary(DLL_Handle); End End
不过从字面上来看,和EXE中的MAIN函数差不多吧.
DELPHI编写的DLL中没有这种函数.但是可以给DLLPROC变量赋值.
1、在VC++的.cpp文件中说明输出函数的名字、类型、调用方式、定义函数执行体:
extern "C" __declspec(dllexport) void VCvoidfunction(......)
{
.......
return;
} extern "C" __declspec(dllexport) DWORD VCdwordfunction(......)
{
.......
return ....;
} 2、在Delphi中说明,假定做一个单独的引入单元:
1)说明函数类型:
Type TVCvoidfunction=Function(......); Cdecl; //函数类型
Type TVCdwordfunction=Function(......); Cdecl; //函数类型 2)定义函数变量:
Var VCvoidfunction: TVCvoidfunction;
VCdwordfunction: TVCdwordfunction; 3、在Delphi程序中首先动态连接DLL: DLL_Handle:=LoadLibrary(PChar(DLLPath));
DLL_Handle>0 Then //若加载成功,
Begin //则依次定位函数
Try
@VCvoidfunction :=GetProcAddress(DLL_Handle,'VCvoidfunction');
@VCdwordfunction:=GetProcAddress(DLL_Handle,'VCdwordfunction);
Except
FreeLibrary(DLL_Handle);
End
End
4、在Delphi程序中调用VC的DLL中函数:
直接使用函数名,按Delphi的要求使用。
注意,VC参数中的&对应Delphi的Var。(本回复来自 http://expert.csdn.net/Expert/topic/2237/2237804.xml?temp=.23164)