Man*_*oor 15 dll static visual-c++
我有.lib文件及其标题(.h)文件.此文件有一些需要在C#应用程序中使用的函数.
谷歌搜索后,我发现我需要从这个静态库创建一个动态DLL,并使用interop从C#代码调用这个动态DLL.
包含头文件并将.lib添加到其他依赖项.
我能够看到静态库中定义的函数(当我按ctrl + space时).
作为一个新手我不知道如何导出该函数,即.lib中有以下签名:
void testfun( char* inp_buff, unsigned short* inp_len, char* buffer_decomp,unsigned *output_len,unsigned short *errorCode)
Run Code Online (Sandbox Code Playgroud)
我想在我的动态DLL中使用不同名称的相同签名.
在头文件和.cpp文件中写什么?
如果可以重新编译lib,只需添加__declspec(dllexport)要导出的所有函数的签名即可.
void __declspec(dllexport) testfun( char* inp_buff, unsigned short* inp_len, char* buffer_decomp,unsigned *output_len,unsigned short *errorCode)
Run Code Online (Sandbox Code Playgroud)
如果你不能这样做,那么你可以通过编写.def文件来导出它们.使用def文件甚至可以在导出时更改函数的名称. http://msdn.microsoft.com/en-us/library/28d6s79h.aspx
---- mylib.def的内容----
LIBRARY
EXPORTS
testfun
newname=testfun2
Run Code Online (Sandbox Code Playgroud)
然后当你链接dll时,包括mylib.def
link /dll /machine:x86 /def:mylib.def mylib.lib
Run Code Online (Sandbox Code Playgroud)
请注意,pinvoke假定您导入的函数将具有_stdcall调用约定,除非您另有说明.因此,您可能需要在C#代码中执行此操作.
[DllImport("mylib.dll", CallingConvention=CallingConvention.Cdecl)]
Run Code Online (Sandbox Code Playgroud)
或者,您可以将C++代码更改为__stdcall
void __declspec(dllexport) __stdcall testfun( char* inp_buff, ...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31292 次 |
| 最近记录: |