留言与评论(共有 0 条评论) |
发布时间:2020-04-15 16:39:56
有两种方法,一种是直接DllImport,就如下面几个的写法,函数名和参数返回值,要跟dll中一至,注意,C#类型与C不一样,如C#中int相当于C++中long等。
[DllImport("kernel32.dll")]//加载dll
publicexternstaticIntPtrLoadLibrary(stringpath);
[DllImport("kernel32.dll")]//获取函数入口指针
publicexternstaticIntPtrGetProcAddress(IntPtrlib,stringfuncName);
[DllImport("kernel32.dll")]//释放dll
publicexternstaticIntPtrFreeLibrary(IntPtrlib);
还有另一种方法(某些sdk用这种方法更安全):
1。先定委托类型,定义与dll中函数一至
2.Intptrhandle=LoadLibrary("a.dll");//加载动链
3.函数入口Intprtt=GetProcAddress(handle,"函数名");
4。将函数入口转换为委托delegateSystem.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(t...)
5.调用委托!
留言与评论(共有 0 条评论) |
全站搜索