[英]'System.EntryPointNotFoundException' when trying to call unmanaged function from C#
I finally have a completed C++ DLL but I'm having trouble calling it from C#. 我终于有一个完整的C ++ DLL,但我无法从C#调用它。 It is definitely finding the DLL as when I remove it from the folder I get a different exception, 'DLLNotFoundException'.
它肯定是找到DLL当我从文件夹中删除它时,我得到一个不同的例外,'DLLNotFoundException'。 The full error description is "Unable to find an entry point named 'GetNewInstance' in DLL 'CComms.dll'".
完整的错误描述是“无法在DLL'CComms.dll'中找到名为'GetNewInstance'的入口点”。 The functions are all exported in C++ like so
这些函数都是用C ++导出的
__declspec(dllexport) DWORD __stdcall GetNewInstance();
and I call it from C# like so 我从C#这样称呼它
[DllImport("CComms.dll")]
private static extern uint GetNewInstance();
// ... and in main
uint inst = GetNewInstance();
When I use 'dumpbin /exports CComms.dll' I get some wierd output I'm not sure whether the function name is being mangled and that's why it cant find an entry point 当我使用'dumpbin / exports CComms.dll'时,我得到一些奇怪的输出我不确定函数名是否被破坏,这就是为什么它找不到入口点
7 6 00002FB0 ?GetNewInstance@@YGKXZ = ?GetNewInstance@@YGKXZ (unsigned long
__stdcall GetNewInstance(void))
I've tried using __cdecl instead of __stdcall, and had the same result. 我已经尝试使用__cdecl而不是__stdcall,并且具有相同的结果。 I'm so close to being done with this project, which I've loated all the way through, hopefully this is the last thing in my way.
我已经接近完成了这个项目,我已经完成了这项工作,希望这是我的最后一件事。
Thanks. 谢谢。
Has the same problem with VB.NE Didn't get this exception if function declared without __stdcall but had Managed Debugging Assistant 'PInvokeStackImbalance' warning. 与VB.NE有相同的问题如果函数声明没有__stdcall但具有托管调试助手'PInvokeStackImbalance'警告,则没有得到此异常。
in the library function declared 在声明的库函数中
extern "C" _declspec(dllexport)
int __stdcall GetLine(HWND hwnd, int iLine, TCHAR *buff)
Adde exports.def file to the dll project 将exports.def文件添加到dll项目中
EXPORT
GetLine
and to the linker Additional Options 和链接器附加选项
/DEF:"exports.def"
problem solved 问题解决了
You have 2 ways of creating a DLL. 您有两种创建DLL的方法。
One is by getting the addresses of the functions (the oldschool way), and the second is by parameters and name (the "new" way, used by .net for example). 一种是通过获取函数的地址(oldschool方式),第二种是通过参数和名称(“新”方式,例如.net使用)。
I imagine you are not using your C++ dll correctly 我想你没有正确使用你的C ++ DLL
Maybe you should be using GetProcAddress
GetProcAddress Msdn 也许你应该使用
GetProcAddress
GetProcAddress Msdn
Here is some documentation concerning Dll exportation which might come in useful 这里有一些关于Dll导出的文档可能会有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.