Well, I use the following approach.
DLL, , , :
#pragma data_seg(".MyShared")
LPTHREAD_START_ROUTINE g_lpMyFunc = NULL;
#pragma data_seg()
#pragma section(".MyShared", read, write, shared)
g_lpMyFunc DllMain :
BOOL APIENTRY DllMain(HMODULE, DWORD dwReasonForCall, LPVOID)
{
if (NULL != GetModuleHandle(_T("MyApp.exe")))
{
if (DLL_PROCESS_ATTACH == dwReasonForCall)
{
g_lpMyFunc = (LPTHREAD_START_ROUTINE)&MyFunc;
}
else if (DLL_PROCESS_DETACH == dwReasonForCall)
{
g_lpMyFunc = NULL;
}
}
return TRUE;
}
. GetModuleHandle MyApp. , , NULL, , DLL DllMain . , MyFunc g_lpMyFunc. DLL ( , ), g_lpMyFunc NULL, , .
MyFuncExtern, MyFunc :
extern "C" __declspec(dllexport) bool __cdecl MyFuncExtern(HANDLE hProcess)
{
if (NULL == g_lpMyFunc)
{
return false;
}
return NULL != CreateRemoteThread(hProcess, NULL, 0, g_lpMyFunc, NULL, 0, NULL);
}
, : g_lpMyFunc NULL, hProcess ( ), , g_lpMyFunc.
, , CreateRemoteThread ( , ), , , DWORD.
Initialize/Uninitialize , , DLL ++/CLI.
, , . .