[pywin32-checkins] /hgroot/pywin32/pywin32: Fix issue implementing COM objects from...
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2012-12-27 05:38:15
|
changeset 860ef545eb60 in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=860ef545eb60 summary: Fix issue implementing COM objects from within a virtualenv (Kevin Smyth via issue #3597965) diffstat: CHANGES.txt | 3 +++ com/win32com/src/PythonCOMLoader.cpp | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diffs (64 lines): diff -r 1d7a40349e7c -r 860ef545eb60 CHANGES.txt --- a/CHANGES.txt Mon Dec 17 11:31:28 2012 -0500 +++ b/CHANGES.txt Thu Dec 27 16:37:57 2012 +1100 @@ -6,6 +6,9 @@ Since build 218: ---------------- +* Fix issue implementing COM objects from within a virtualenv (Kevin Smyth + via issue #3597965) + * win32com.shell Add interfaces IFileOperation and IFileOperationProgressSink diff -r 1d7a40349e7c -r 860ef545eb60 com/win32com/src/PythonCOMLoader.cpp --- a/com/win32com/src/PythonCOMLoader.cpp Mon Dec 17 11:31:28 2012 -0500 +++ b/com/win32com/src/PythonCOMLoader.cpp Thu Dec 27 16:37:57 2012 +1100 @@ -17,6 +17,7 @@ static PFN_DEACTIVATEACTCTX pfnDeactivateActCtx = NULL; static PFN_ADDREFACTCTX pfnAddRefActCtx = NULL; static PFN_RELEASEACTCTX pfnReleaseActCtx = NULL; +static HINSTANCE hinstThisModule = NULL; void _LoadActCtxPointers() { @@ -68,8 +69,21 @@ if (pfnDllGetClassObject==0) { // before loading pythoncom we must activate our context so // the CRT loads correctly. + HMODULE hpycom = NULL; ULONG_PTR cookie = _Py_ActivateActCtx(); - HMODULE hpycom = LoadLibraryEx(DLL_DELEGATE, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + TCHAR loader_path[MAX_PATH]; + if (GetModuleFileName(hinstThisModule, loader_path, MAX_PATH) != 0) { + TCHAR fullpath[MAX_PATH]; + TCHAR* filepart; + if (GetFullPathName(loader_path, MAX_PATH, fullpath, &filepart) != 0 && filepart != NULL) { + if (_tcslen(DLL_DELEGATE) + _tcslen(loader_path) < sizeof(fullpath) / sizeof(fullpath[0])) { + _tcscpy(filepart, DLL_DELEGATE); + hpycom = LoadLibraryEx(fullpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + } + } + } + if (hpycom == NULL) + hpycom = LoadLibrary(DLL_DELEGATE); _Py_DeactivateActCtx(cookie); if (hpycom) { pfnDllGetClassObject = (PFNDllGetClassObject)GetProcAddress(hpycom, _T("DllGetClassObject")); @@ -82,7 +96,7 @@ } -BOOL WINAPI DllMain (HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) +BOOL WINAPI DllMain (HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: @@ -92,6 +106,7 @@ if ((*pfnGetCurrentActCtx)(&PyWin_DLLhActivationContext)) if (!(*pfnAddRefActCtx)(PyWin_DLLhActivationContext)) OutputDebugString("pythoncomloader failed to load the default activation context\n"); + hinstThisModule = hInst; break; case DLL_PROCESS_DETACH: |