views:

276

answers:

1

Hello

I am using the Mfc to Qt migration solution, to migrate my Mfc plugin to Qt. My Mfc plugin is loaded in third party Mfc app. Basically I am using the following example Qt based Application Extension :

BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID  ) {
 static bool ownApplication = FALSE;
 if ( dwReason == DLL_PROCESS_ATTACH )
     ownApplication = QMfcApp::pluginInstance( hInstance );
 if ( dwReason == DLL_PROCESS_DETACH && ownApplication )
     delete qApp;
 return TRUE;
}

I read the code of pluginInstance function, int the Qt Sources,and notice that pluginInstance calls LoadLibrary and SetWindowsHook inside.

Everything is working ok , so far . But I have the following concern : It is forbidden to call LoadLibrary and functions from user32.dll like SetWindowsHook from DllMain. I read that in msdn doc for DllMain. So , if this is unsafe why the offical Qt site says to call pluginInstance in DllMain? Qt based Application Extension Maybe I am missing something

A: 

maybe they didn't read it :), but it's safe to call LoadLibrary() for a DLL that doesn't call other 'unsafe' apis like CreateThread() etc., it's just a suggestion, just think yourself what's going on when you call LoadLibrary() from DLL_PROCESS_ATTACH, library gets loaded, IAT filled and DllMain() called.

Bartosz Wójcik