如何设置一个dll的入口点 [英] How can i set an entrypoint for a dll
问题描述
首先我想到dll DLLMain的入口点,但是当我尝试在C#中导入它时,我得到一个错误entrypoint没有找到这里是我的代码:
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;
}
如何设置我的dll的入口点?如果你不介意你能给我很少解释关于入口点吗?
How can i set an entry point for my dll? And if you dont mind can you give me little explanation about entry point?
像我必须设置导入相同的dll,改变入口点,所以我可以使用其他功能在同一dll? 。
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.
推荐答案
在你的例子中,你似乎想要Test()成为一个入口点,导出。即使您开始导出它,它可能无法正常工作与C ++名称装饰(万岁)。我建议重新定义你的函数为:
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:
extern "C" __declspec(dllexport) int Test(int x,int y)
externC
C ++名称调整。 __ declspec(dllexport)
组件导出符号。
The extern "C"
component will remove C++ name mangling. The __declspec(dllexport)
component exports the symbol.
请参阅http://zone.ni.com/devzone/cda/tut/p/id/3056 了解详情。
编辑:您可以按照这种方式添加任意数量的入口点。调用代码只需要知道要检索的符号的名称(如果你正在创建一个静态的.lib,它会为你处理它)。
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).
这篇关于如何设置一个dll的入口点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!