[issue19790] ctypes can't load a c++ dll if the dll calls COM on Windows 8
New submission from yinkaisheng: I created a c++ dll project that calls COM. cyptes works well with the dll on Windows XP(SP3) and Windows 7. But it can't load the dll on windows 8. The function ctypes.cdll.LoadLibrary doesn't return when I call it to load the dll on Windows 8. The version of my Python is 2.7.6 The version of my Windows 8 is 6.2.9200.16384 I uploaded a sample dll project created by VS2012 as the attachment. Here are the c++ codes // dllmain.cpp : #include "stdafx.h" #include #include IUIAutomation *g_pAutomation = NULL; #define DLL_EXPORT __declspec(dllexport) BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: { if (NULL == g_pAutomation) { CoInitialize(NULL); HRESULT hr = CoCreateInstance(__uuidof(CUIAutomation), NULL, CLSCTX_INPROC_SERVER, __uuidof(IUIAutomation), (void**)&g_pAutomation); } break; } case DLL_THREAD_ATTACH: { break; } case DLL_THREAD_DETACH: { break; } case DLL_PROCESS_DETACH: { if (g_pAutomation) { g_pAutomation->Release(); CoUninitialize(); } break; } } return TRUE; } #ifdef __cplusplus extern "C" { #endif DLL_EXPORT int AddTwoNumber(int a, int b) { return a + b; } #ifdef __cplusplus } #endif -- components: ctypes files: TestDll.rar messages: 204454 nosy: yinkaisheng priority: normal severity: normal status: open title: ctypes can't load a c++ dll if the dll calls COM on Windows 8 type: behavior versions: Python 2.7 Added file: http://bugs.python.org/file32849/TestDll.rar ___ Python tracker <http://bugs.python.org/issue19790> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19790] ctypes can't load a c++ dll if the dll calls COM on Windows 8
yinkaisheng added the comment: The version of my Python is 2.7.5.6 -- ___ Python tracker <http://bugs.python.org/issue19790> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19790] ctypes can't load a c++ dll if the dll calls COM on Windows 8
yinkaisheng added the comment: After debugging, I found the reason. when ctypes loads the dll, CoCreateInstance blocks the flow. If I don't call CoCreateInstance in function DllMain. ctypes can load the dll. I should call function CoCreateInstance after DllMain was called. The problem was fixed. -- resolution: -> wont fix status: open -> closed ___ Python tracker <http://bugs.python.org/issue19790> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue19790] ctypes can't load a c++ dll if the dll calls COM on Windows 8
yinkaisheng added the comment: http://support.microsoft.com/kb/305723 COM application hangs when you call CoCreateInstance from DllMain SYMPTOMS When you call the CoCreateInstance function from the DllMain function, the Component Object Model (COM) application hangs. CAUSE CoCreateInstance may start a thread that tries to call the DllMain function of all dynamic-link libraries (DLLs) that exist in the process by passing a DLL_THREAD_ATTACH value. Because the call originates from DllMain, and because DllMain is not a reentrant function, the call to CoCreateInstance never returns. RESOLUTION To resolve this problem, do not call CoCreateInstance from DllMain. You can move the call to an initialization function or to any other function that is called later. STATUS This behavior is by design. -- ___ Python tracker <http://bugs.python.org/issue19790> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com