我有一个c ++ dll,从c#进程调用...
[DllImport(@"My.dll", EntryPoint = "Function1", CallingConvention = CallingConvention.Cdecl)]
public static extern bool MyFunction(int id1, int id2, [MarshalAsAttribute(UnmanagedType.LPWStr)] StringBuilder Name);
这是dll入口点......
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
std::cout << "Attach" << std::endl;
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
std::cout << "Detach" << std::endl;
break;
}
我得到一个附件和四个分离像这样...
附加 分离 分离 分离 分离
任何人都可以解释原因吗?
该过程仅对该函数进行一次调用。
答案 0 :(得分:3)
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
std::cout << "Detach" << std::endl;
break;
当DLL_THREAD_ATTACH
,DLL_THREAD_DETACH
或DLL_PROCESS_DETACH
被触发时,您的代码将在控制台中写入“分离”。如果您只想在DLL_PROCESS_DETACH
中添加break
个switch
语句:
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
std::cout << "Attach" << std::endl;
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
std::cout << "Detach" << std::endl;
break;
}
或者只是省略未使用的案例。