从C ++ DLL导出方法,C#。为什么需要:" EXTERN" C" " [英] Export dll method from C++ to C#. Why I need: " extern "C" "
本文介绍了从C ++ DLL导出方法,C#。为什么需要:" EXTERN" C" "的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的DLL有,我要导出的方法
In my dll there is a method that I want to export.
//作品:
extern "C" __declspec(dllexport)
//不会工作
__declspec(dllexport)
C ++出口:
extern "C" __declspec(dllexport) int Test();
C#导入:
C# import:
[DllImport("CircleGPU2_32.DLL", EntryPoint = "Test",
CallingConvention = CallingConvention.StdCall)]
public static extern int Test();
为什么我需要在的externC
推荐答案
的主要原因是为了防止C ++名字压榨机从重整的函数的名称。
The main reason is to prevent the C++ name mangler from mangling the name of the function.
尝试没有的externC将其导出
并检查在Dependency Walker中所产生的DLL,你会看到一个完全不同的名称的导出函数。
Try exporting it without the extern "C"
and inspect the resulting DLL in Dependency Walker and you will see a quite different name for the exported function.
这篇关于从C ++ DLL导出方法,C#。为什么需要:" EXTERN" C" "的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文