From 0c20eac9b081cd9c1c81dfbc3e48e069f859edc1 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 5 Nov 2017 17:42:58 +0300 Subject: AssocMsg: fix for launching it via rundll32 --- plugins/AssocMgr/assocmgr.vcxproj | 6 +++++ plugins/AssocMgr/src/assocmgr.def | 4 ++++ plugins/AssocMgr/src/dde.cpp | 50 ++++++++++++++++----------------------- plugins/AssocMgr/src/main.cpp | 21 ++++++++++++++++ plugins/AssocMgr/src/stdafx.h | 3 +++ plugins/AssocMgr/src/version.h | 14 +++++------ 6 files changed, 62 insertions(+), 36 deletions(-) create mode 100644 plugins/AssocMgr/src/assocmgr.def (limited to 'plugins') diff --git a/plugins/AssocMgr/assocmgr.vcxproj b/plugins/AssocMgr/assocmgr.vcxproj index ec8afbf2d1..553603b7f8 100644 --- a/plugins/AssocMgr/assocmgr.vcxproj +++ b/plugins/AssocMgr/assocmgr.vcxproj @@ -25,4 +25,10 @@ + + + api-ms-win-crt-convert-l1-1-0.dll;api-ms-win-crt-runtime-l1-1-0.dll;api-ms-win-crt-string-l1-1-0.dll;mir_app.mir;mir_core.mir;VCRUNTIME140.dll + src/assocmgr.def + + \ No newline at end of file diff --git a/plugins/AssocMgr/src/assocmgr.def b/plugins/AssocMgr/src/assocmgr.def new file mode 100644 index 0000000000..7a3f973545 --- /dev/null +++ b/plugins/AssocMgr/src/assocmgr.def @@ -0,0 +1,4 @@ +LIBRARY AssocMgr.dll + +EXPORTS +WaitForDDE @1 \ No newline at end of file diff --git a/plugins/AssocMgr/src/dde.cpp b/plugins/AssocMgr/src/dde.cpp index f6c52a67df..13da3b00eb 100644 --- a/plugins/AssocMgr/src/dde.cpp +++ b/plugins/AssocMgr/src/dde.cpp @@ -182,39 +182,31 @@ static HANDLE StartupMainProcess(wchar_t *pszDatabasePath) return pi.hProcess; } -#ifdef __cplusplus -extern "C" { -#endif - - // entry point for RunDll32, this is also WaitForDDEW - __declspec(dllexport) void CALLBACK WaitForDDE(HWND, HINSTANCE, wchar_t *pszCmdLine, int) - { - HANDLE pHandles[2]; - DWORD dwTick; - - /* wait for dde window to be available (avoiding race condition) */ - pHandles[0] = CreateEvent(NULL, TRUE, FALSE, WNDCLASS_DDEMSGWINDOW); - if (pHandles[0] != NULL) { - pHandles[1] = StartupMainProcess(pszCmdLine); /* obeys nCmdShow using GetStartupInfo() */ - if (pHandles[1] != NULL) { - dwTick = GetTickCount(); - /* either process terminated or dde window created */ - if (WaitForMultipleObjects(_countof(pHandles), pHandles, FALSE, DDEMESSAGETIMEOUT) == WAIT_OBJECT_0) { - dwTick = GetTickCount() - dwTick; - if (dwTick < DDEMESSAGETIMEOUT) - WaitForInputIdle(pHandles[1], DDEMESSAGETIMEOUT - dwTick); - } - CloseHandle(pHandles[1]); +// 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; + + /* wait for dde window to be available (avoiding race condition) */ + pHandles[0] = CreateEvent(NULL, TRUE, FALSE, WNDCLASS_DDEMSGWINDOW); + if (pHandles[0] != NULL) { + pHandles[1] = StartupMainProcess(pszCmdLine); /* obeys nCmdShow using GetStartupInfo() */ + if (pHandles[1] != NULL) { + dwTick = GetTickCount(); + /* either process terminated or dde window created */ + if (WaitForMultipleObjects(_countof(pHandles), pHandles, FALSE, DDEMESSAGETIMEOUT) == WAIT_OBJECT_0) { + dwTick = GetTickCount() - dwTick; + if (dwTick < DDEMESSAGETIMEOUT) + WaitForInputIdle(pHandles[1], DDEMESSAGETIMEOUT - dwTick); } - CloseHandle(pHandles[0]); + CloseHandle(pHandles[1]); } - /* shell called WaitForInputIdle() on us to detect when dde is ready, - * we are ready now: exit helper process */ + CloseHandle(pHandles[0]); } - -#ifdef __cplusplus + /* shell called WaitForInputIdle() on us to detect when dde is ready, + * we are ready now: exit helper process */ } -#endif /************************* Misc ***********************************/ diff --git a/plugins/AssocMgr/src/main.cpp b/plugins/AssocMgr/src/main.cpp index ddc2075d52..10bd63eaf9 100644 --- a/plugins/AssocMgr/src/main.cpp +++ b/plugins/AssocMgr/src/main.cpp @@ -21,6 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" +#pragma comment(lib, "delayimp.lib") + HINSTANCE hInst; static HANDLE hHookModulesLoaded; int hLangpack; @@ -39,6 +41,25 @@ 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) { hInst = hinstDLL; diff --git a/plugins/AssocMgr/src/stdafx.h b/plugins/AssocMgr/src/stdafx.h index 89cf724b45..6c93da6e33 100644 --- a/plugins/AssocMgr/src/stdafx.h +++ b/plugins/AssocMgr/src/stdafx.h @@ -24,6 +24,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include +#define DELAYIMP_INSECURE_WRITABLE_HOOKS +#include + #include #include #include diff --git a/plugins/AssocMgr/src/version.h b/plugins/AssocMgr/src/version.h index b6d649a810..df73ec2cb1 100644 --- a/plugins/AssocMgr/src/version.h +++ b/plugins/AssocMgr/src/version.h @@ -19,17 +19,17 @@ 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. */ -#define __MAJOR_VERSION 0 -#define __MINOR_VERSION 1 -#define __RELEASE_NUM 1 +#define __MAJOR_VERSION 0 +#define __MINOR_VERSION 2 +#define __RELEASE_NUM 1 #define __BUILD_NUM 0 #include #define __PLUGIN_NAME "File association manager" #define __FILENAME "AssocMgr.dll" -#define __DESCRIPTION "Handles file type associations and URLs like aim, gg, mirpu, tlen, wpmsg, xmpp, ymsgr." -#define __AUTHOR "H. Herkenrath" +#define __DESCRIPTION "Handles file type associations and URLs like aim, gg, mirpu, tlen, wpmsg, xmpp, ymsgr." +#define __AUTHOR "H. Herkenrath" #define __AUTHOREMAIL "hrathh@users.sourceforge.net" -#define __AUTHORWEB "https://miranda-ng.org/p/AssocMgr/" -#define __COPYRIGHT "© 2005-2007 H. Herkenrath" +#define __AUTHORWEB "https://miranda-ng.org/p/AssocMgr/" +#define __COPYRIGHT "© 2005-2007 H. Herkenrath" -- cgit v1.2.3