diff options
author | George Hazan <ghazan@miranda.im> | 2017-11-25 23:13:02 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-11-25 23:13:02 +0300 |
commit | 4657d391c9f213c788e32347c083f2699aed672e (patch) | |
tree | 4c8d0376046ed3eec758534d5cd2f0a97dba48ce /plugins/AssocMgr | |
parent | 71d2aa24a344c6e45d4632ea99fa1e5006367733 (diff) |
more accurate solution for AssocMgr that doesn't change current working directory
Diffstat (limited to 'plugins/AssocMgr')
-rw-r--r-- | plugins/AssocMgr/src/dde.cpp | 7 | ||||
-rw-r--r-- | plugins/AssocMgr/src/main.cpp | 17 | ||||
-rw-r--r-- | plugins/AssocMgr/src/utils.cpp | 18 | ||||
-rw-r--r-- | plugins/AssocMgr/src/utils.h | 2 |
4 files changed, 24 insertions, 20 deletions
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 @@ -42,23 +42,6 @@ PLUGININFOEX pluginInfo = { };
/////////////////////////////////////////////////////////////////////////////////////////
-// 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);
|