C#项目中使用 using System.Runtime.InteropServices//需要使用的组件命名空间
[DllImport("WDT_DIO64.dll")]//导出C语言的DLL文件(我的WDT_DIO64.dll)
internal static extern int InitDIO()//导出C语言的功能函数接口(我的int InitDIO())
然后就可以在需要功能函数引用位置 使用功能函数。
一 调用静态载入1 客户端函数声名:
1)笮⌒疵舾小?br />
2)与DLL中的声明一样。
如: showform(form:Tform)Farexternal\'yproject_dll.dll\'
3)调用时传过去的参数类型最好也与windows c++一样。
4)调用时DLL必须在windows搜索路径中,顺序是:当前目录;Path路径;windowswidowswindows
二 调用动态载入
1 建立一种过程类型[如果你对过程类型的变量只是一个指针的本质清楚的话,你就知道是怎么回事了]。如:
type
mypointer=procedure(form:Tform)Farexternal
var
Hinst:Thandle
showform:mypointer
begin
Hinst:=loadlibrary(\'yproject_dll\')//Load一个Dll,按文件名找。
showform:=getprocaddress(Hinst,\'showform\')//按函数名找,大小写敏感。如果你知道自动化对象的本质就清楚了。
showform(application.mainform)//找到函数入口指针就调用。
Freelibrary(Hinst)
end