From 4657d391c9f213c788e32347c083f2699aed672e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 25 Nov 2017 23:13:02 +0300 Subject: more accurate solution for AssocMgr that doesn't change current working directory --- plugins/AssocMgr/src/dde.cpp | 7 ++++--- plugins/AssocMgr/src/main.cpp | 17 ----------------- plugins/AssocMgr/src/utils.cpp | 18 ++++++++++++++++++ plugins/AssocMgr/src/utils.h | 2 ++ 4 files changed, 24 insertions(+), 20 deletions(-) (limited to 'plugins/AssocMgr') diff --git a/plugins/AssocMgr/src/dde.cpp b/plugins/AssocMgr/src/dde.cpp index 0e9d29fb0e..d1b4f30fa5 100644 --- a/plugins/AssocMgr/src/dde.cpp +++ b/plugins/AssocMgr/src/dde.cpp @@ -185,15 +185,16 @@ static HANDLE StartupMainProcess(wchar_t *pszDatabasePath) // entry point for RunDll32, this is also WaitForDDEW EXTERN_C __declspec(dllexport) void CALLBACK WaitForDDE(HWND, HINSTANCE, wchar_t *pszCmdLine, int) { - HANDLE pHandles[2]; - DWORD dwTick; + // executed to initialize path for delay-loaded libraries + DynamicLoadInit(); /* wait for dde window to be available (avoiding race condition) */ + HANDLE pHandles[2]; pHandles[0] = CreateEvent(nullptr, TRUE, FALSE, WNDCLASS_DDEMSGWINDOW); if (pHandles[0] != nullptr) { pHandles[1] = StartupMainProcess(pszCmdLine); /* obeys nCmdShow using GetStartupInfo() */ if (pHandles[1] != nullptr) { - dwTick = GetTickCount(); + DWORD dwTick = GetTickCount(); /* either process terminated or dde window created */ if (WaitForMultipleObjects(_countof(pHandles), pHandles, FALSE, DDEMESSAGETIMEOUT) == WAIT_OBJECT_0) { dwTick = GetTickCount() - dwTick; diff --git a/plugins/AssocMgr/src/main.cpp b/plugins/AssocMgr/src/main.cpp index 8f2fe1551b..5f7d515073 100644 --- a/plugins/AssocMgr/src/main.cpp +++ b/plugins/AssocMgr/src/main.cpp @@ -41,23 +41,6 @@ PLUGININFOEX pluginInfo = { {0x52685cd7, 0xec7, 0x44c1, {0xa1, 0xa6, 0x38, 0x16, 0x12, 0x41, 0x82, 0x2}} }; -///////////////////////////////////////////////////////////////////////////////////////// -// if we run here, we're running from the command prompt - -static bool bPathSet = false; - -FARPROC WINAPI myDliHook(unsigned dliNotify, PDelayLoadInfo) -{ - if (dliNotify == dliNotePreLoadLibrary && !bPathSet) { - bPathSet = true; - SetCurrentDirectoryW(L"Libs"); - LoadLibraryW(L"ucrtbase.dll"); - } - return NULL; -} - -PfnDliHook __pfnDliNotifyHook2 = &myDliHook; - ///////////////////////////////////////////////////////////////////////////////////////// BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) diff --git a/plugins/AssocMgr/src/utils.cpp b/plugins/AssocMgr/src/utils.cpp index 8495d9da7a..02718bd02f 100644 --- a/plugins/AssocMgr/src/utils.cpp +++ b/plugins/AssocMgr/src/utils.cpp @@ -21,6 +21,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" +void DynamicLoadInit() +{ + wchar_t wszPath[MAX_PATH]; + GetModuleFileNameW(nullptr, wszPath, _countof(wszPath)); + + for (int i = lstrlenW(wszPath); i >= 0; i--) + if (wszPath[i] == '\\') { + wszPath[i + 1] = 0; + break; + } + + lstrcatW(wszPath, L"\\libs"); + SetDllDirectoryW(wszPath); + + lstrcatW(wszPath, L"\\ucrtbase.dll"); + LoadLibraryW(wszPath); +} + /************************* String Conv ****************************/ // mir_free() the return value diff --git a/plugins/AssocMgr/src/utils.h b/plugins/AssocMgr/src/utils.h index 3db6bf09e6..802b74d94b 100644 --- a/plugins/AssocMgr/src/utils.h +++ b/plugins/AssocMgr/src/utils.h @@ -19,6 +19,8 @@ along with this program (AssocMgr-License.txt); if not, write to the Free Softwa Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +void DynamicLoadInit(); + /* String Conv */ WCHAR* a2u(const char *pszAnsi,BOOL fMirCp); char* u2a(const WCHAR *pszUnicode,BOOL fMirCp); -- cgit v1.2.3