DllMain and Qt Mfc Migration

随声附和 提交于 2019-12-24 18:57:22

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/1678937/dllmain-and-qt-mfc-migration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!