如何设置 dll 的入口点
首先,我认为 dll 中的入口点是 DLLMain,但是当我尝试在 C# 中导入它时,我收到一条错误,找不到入口点 这是我的代码:
#include <Windows.h>
int Test(int x,int y)
{
return x+y;
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
MessageBox(0,L"Test",L"From unmanaged dll",0);
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
如何为我的 dll 设置入口点?如果您不介意的话,您能给我一些关于入口点的解释吗?
就像我是否必须再次设置导入相同的 dll 并更改入口点,以便我可以在同一 dll 中使用其他函数?提前致谢。
First i thought entry point in dlls DLLMain but then when i try to import it in C# i get an error that entrypoint wasn't found Here is my code:
#include <Windows.h>
int Test(int x,int y)
{
return x+y;
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
MessageBox(0,L"Test",L"From unmanaged dll",0);
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
How can i set an entry point for my dll? And if you dont mind can you give me little explanation about entry point?
Like do i have to set import the same dll again and changing the entry point so i can use other functions in same dll? thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的示例中,您似乎打算将 Test() 作为入口点,但您并未导出它。即使您开始导出它,它也可能无法与 C++ 名称“装饰”(重整)一起正常工作。我建议将您的函数重新定义为:
extern "C"
组件将删除 C++ 名称修改。__declspec(dllexport)
组件导出符号。请参阅http://zone.ni.com/devzone/cda/tut/ p/id/3056 了解更多详细信息。
编辑:您可以通过这种方式添加任意多个入口点。调用代码只需知道要检索的符号的名称(如果您要创建静态 .lib,它会为您处理它)。
In your example, it seems you intend Test() to be an entry point however you aren't exporting it. Even if you begin exporting it, it might not work properly with C++ name "decoration" (mangling). I'd suggest redefining your function as:
The
extern "C"
component will remove C++ name mangling. The__declspec(dllexport)
component exports the symbol.See http://zone.ni.com/devzone/cda/tut/p/id/3056 for more detail.
Edit: You can add as many entry points as you like in this manner. Calling code merely must know the name of the symbol to retrieve (and if you're creating a static .lib, that takes care of it for you).