【发布时间】:2014-12-18 13:51:54
【问题描述】:
以下是在服务器上首次调用 DLL 时如何编写 C++ 功能来执行某些操作。在 C# 类库中如何做到这一点?对于 Visual Studio 中的类库项目,属性中的启动是灰色的(禁用),但需要是库,因为我在我的 Web 应用程序中使用它作为参考。并且不知道如何在 C# 中编写等效的代码,因此我可以编写一些代码来在加载或启动 dll 时记录事件。
BOOL WINAPI DllMain(
HINSTANCE hinstDLL, // handle to DLL module
DWORD fdwReason, // reason for calling function
LPVOID lpReserved ) // reserved
{
// Perform actions based on the reason for calling.
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
// Initialize once for each new process.
// Here is where the module POST should be invoked
// Return FALSE to fail DLL load in case POST fails
break;
case DLL_THREAD_ATTACH:
// Do thread-specific initialization.
break;
case DLL_THREAD_DETACH:
// Do thread-specific cleanup.
break;
case DLL_PROCESS_DETACH:
// Perform any necessary cleanup.
break;
}
return TRUE; // Successful DLL_PROCESS_ATTACH.
}
【问题讨论】:
-
因为我在我的 Web 应用程序中使用它作为参考 如果它托管在 IIS 中,请使用该应用程序启动前属性。 dailydotnettips.com/2011/08/27/…
-
“Visual Studio 中的类库项目的属性中的启动是灰色的(禁用),但需要是库,因为我在我的 Web 应用程序中使用它作为参考。” i> -- 你可以像引用类库一样引用其他项目的可执行程序集。
标签: c# c++ multithreading visual-studio startup