Jsem to nepopsal asi moc dobře včera:
DLL:
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
printf("DLL_PROCESS_ATTACH \n");
case DLL_THREAD_ATTACH:
printf("DLL_THREAD_ATTACH \n");
case DLL_THREAD_DETACH:
printf("DLL_THREAD_DETACH \n");
case DLL_PROCESS_DETACH:
printf("DLL_PROCESS_DETACH \n");
break;
}
return TRUE;
}
DWORD DIO_Initialize()
{
printf("From DLL \n");
return 1;
}
C#:
Console.Write("Ret val 1: " + DIO_Initialize() + "\n");
Thread.Sleep(500);
Console.Write("Ret val 2: " + DIO_Initialize() + "\n");
Vypis z console:
DLL_PROCESS_ATTACH
DLL_THREAD_ATTACH
DLL_THREAD_DETACH
DLL_PROCESS_DETACH
From DLL
Ret val 1: 1
From DLL
Ret val 2: 1
DLL_PROCESS_DETACH
Pokud do funkce DIO_Initialize vložím smyčku s výpisem do console (+ sleep 2s), tak dojde k zavolani DllMain i behem vykonavani funkce. Můj selský rozum mi říká, že to nedává smysl, respektive si nedokazu predstavit cokoliv vykonavat v DllMain pri takoveto podivne posloupnosti volani.
DLL_PROCESS_ATTACH
DLL_THREAD_ATTACH
DLL_THREAD_DETACH
DLL_PROCESS_DETACH
From DLL
From DLL
From DLL
From DLL
From DLL
From DLL
From DLL
From DLL
From DLL
From DLL
Ret val 1: 1
From DLL
From DLL
From DLL
From DLL
From DLL
DLL_THREAD_ATTACH
DLL_THREAD_DETACH
DLL_PROCESS_DETACH
DLL_THREAD_ATTACH
DLL_THREAD_DETACH
DLL_PROCESS_DETACH
DLL_THREAD_ATTACH
DLL_THREAD_DETACH
DLL_PROCESS_DETACH
From DLL
From DLL
From DLL
From DLL
From DLL
Ret val 2: 1
DLL_PROCESS_DETACH