我用 dev C++ 编写了一个 DLL。该DLL的名称是“DllMain.dll”,它包含两个函数:HelloWorld
and ShowMe
。头文件如下所示:
DLLIMPORT void HelloWorld();
DLLIMPORT void ShowMe();
源文件如下所示:
DLLIMPORT void HelloWorld ()
{
MessageBox (0, "Hello World from DLL!\n", "Hi",MB_ICONINFORMATION);
}
DLLIMPORT void ShowMe()
{
MessageBox (0, "How are u?", "Hi", MB_ICONINFORMATION);
}
我将代码编译成 DLL 并从 C# 调用这两个函数。 C# 代码如下所示:
[DllImport("DllMain.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void HelloWorld();
[DllImport("DllMain.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void ShowMe();
当我调用函数“HelloWorld”时,它运行良好并弹出一个消息框,但是当我调用该函数时ShowMe
an EntryPointNotFoundException
发生。我该如何避免这种异常?我需要添加吗extern "C"
在头文件中?
以下代码在 VS 2012 中运行良好:
#include <Windows.h>
extern "C"
{
__declspec(dllexport) void HelloWorld ()
{
MessageBox (0, L"Hello World from DLL!\n", L"Hi",MB_ICONINFORMATION);
}
__declspec(dllexport) void ShowMe()
{
MessageBox (0, L"How are u?", L"Hi", MB_ICONINFORMATION);
}
}
NOTE:如果我删除extern "C"
我得到例外。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)