From d6eee2018898f2442883a0aa77ad095b75572cfb Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 27 Aug 2015 15:15:33 +0000 Subject: fix for 64-bit issues & warnings git-svn-id: http://svn.miranda-ng.org/main/trunk@15043 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/AssocMgr/src/dde.cpp | 240 +++++++++++++++++++++---------------------- 1 file changed, 120 insertions(+), 120 deletions(-) (limited to 'plugins/AssocMgr') diff --git a/plugins/AssocMgr/src/dde.cpp b/plugins/AssocMgr/src/dde.cpp index 17706ab018..ba69dd9fac 100644 --- a/plugins/AssocMgr/src/dde.cpp +++ b/plugins/AssocMgr/src/dde.cpp @@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern HINSTANCE hInst; static HWND hwndDdeMsg; /* Misc */ -static HANDLE hHookModulesLoaded,hHookPreShutdown; +static HANDLE hHookModulesLoaded, hHookPreShutdown; /************************* Open Handler ***************************/ @@ -34,13 +34,13 @@ static void __stdcall FileActionAsync(void *param) { TCHAR *pszFilePath = (TCHAR*)param; /* invoke main handler */ - switch(InvokeFileHandler(pszFilePath)) { /* pszFilePath is always a long path name */ - case 0: /* success */ break; - case CALLSERVICE_NOTFOUND: - ShowInfoMessage(NIIF_ERROR,Translate("Miranda NG could not open file"),Translate("Miranda NG was not able to open \"%S\".\n\nThere is no registered handler for this file type."),pszFilePath); - break; - default: - ShowInfoMessage(NIIF_ERROR,Translate("Miranda NG could not open file"),Translate("Miranda NG was not able to open \"%S\".\n\nThe file could not be processed."),pszFilePath); + switch (InvokeFileHandler(pszFilePath)) { /* pszFilePath is always a long path name */ + case 0: /* success */ break; + case CALLSERVICE_NOTFOUND: + ShowInfoMessage(NIIF_ERROR, Translate("Miranda NG could not open file"), Translate("Miranda NG was not able to open \"%S\".\n\nThere is no registered handler for this file type."), pszFilePath); + break; + default: + ShowInfoMessage(NIIF_ERROR, Translate("Miranda NG could not open file"), Translate("Miranda NG was not able to open \"%S\".\n\nThe file could not be processed."), pszFilePath); } mir_free(pszFilePath); /* async param */ } @@ -50,13 +50,13 @@ static void __stdcall UrlActionAsync(void *param) { TCHAR *pszUrl = (TCHAR*)param; /* invoke main handler */ - switch(InvokeUrlHandler(pszUrl)) { - case 0: /* success */ break; - case CALLSERVICE_NOTFOUND: - ShowInfoMessage(NIIF_ERROR,Translate("Miranda NG could not open URL"),Translate("Miranda NG was not able to open \"%S\".\n\nThere is no registered handler for this URL type."),pszUrl); - break; - default: - ShowInfoMessage(NIIF_ERROR,Translate("Miranda NG could not open URL"),Translate("Miranda NG was not able to open \"%S\".\n\nThe given URL is invalid and cannot be parsed."),pszUrl); + switch (InvokeUrlHandler(pszUrl)) { + case 0: /* success */ break; + case CALLSERVICE_NOTFOUND: + ShowInfoMessage(NIIF_ERROR, Translate("Miranda NG could not open URL"), Translate("Miranda NG was not able to open \"%S\".\n\nThere is no registered handler for this URL type."), pszUrl); + break; + default: + ShowInfoMessage(NIIF_ERROR, Translate("Miranda NG could not open URL"), Translate("Miranda NG was not able to open \"%S\".\n\nThe given URL is invalid and cannot be parsed."), pszUrl); } mir_free(pszUrl); /* async param */ } @@ -70,116 +70,117 @@ static void __stdcall UrlActionAsync(void *param) // returns an empty string if the string does not have enough arguments static TCHAR* GetExecuteParam(TCHAR **ppszString) { - TCHAR *pszParam,*p; + TCHAR *pszParam, *p; BOOL fQuoted; - - fQuoted=(**ppszString==_T('"')); - pszParam=*ppszString; - if(fQuoted) pszParam++; - p=_tcschr(pszParam,(TCHAR)(fQuoted?_T('"'):_T(','))); - if(p!=NULL) { - *(p++)=0; - if(fQuoted && *p==_T(',')) p++; - } else p=&pszParam[mir_tstrlen(pszParam)]; - *ppszString=p; + + fQuoted = (**ppszString == _T('"')); + pszParam = *ppszString; + if (fQuoted) pszParam++; + p = _tcschr(pszParam, (TCHAR)(fQuoted ? _T('"') : _T(','))); + if (p != NULL) { + *(p++) = 0; + if (fQuoted && *p == _T(',')) p++; + } + else p = &pszParam[mir_tstrlen(pszParam)]; + *ppszString = p; return pszParam; } -static LRESULT CALLBACK DdeMessageWindow(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) +static LRESULT CALLBACK DdeMessageWindow(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) { - case WM_DDE_INITIATE: + switch (msg) { + case WM_DDE_INITIATE: { - ATOM hSzApp=LOWORD(lParam); /* no UnpackDDElParam() here */ - ATOM hSzTopic=HIWORD(lParam); - if ((hSzApp==GlobalFindAtom(DDEAPP) && hSzTopic==GlobalFindAtom(DDETOPIC)) || !hSzApp) { - hSzApp=GlobalAddAtom(DDEAPP); - hSzTopic=GlobalAddAtom(DDETOPIC); - if(hSzApp && hSzTopic) + ATOM hSzApp = LOWORD(lParam); /* no UnpackDDElParam() here */ + ATOM hSzTopic = HIWORD(lParam); + if ((hSzApp == GlobalFindAtom(DDEAPP) && hSzTopic == GlobalFindAtom(DDETOPIC)) || !hSzApp) { + hSzApp = GlobalAddAtom(DDEAPP); + hSzTopic = GlobalAddAtom(DDETOPIC); + if (hSzApp && hSzTopic) /* PackDDElParam() only for posted msgs */ - SendMessage((HWND)wParam,WM_DDE_ACK,(WPARAM)hwnd,MAKELPARAM(hSzApp,hSzTopic)); - if(hSzApp) GlobalDeleteAtom(hSzApp); - if(hSzTopic) GlobalDeleteAtom(hSzTopic); + SendMessage((HWND)wParam, WM_DDE_ACK, (WPARAM)hwnd, MAKELPARAM(hSzApp, hSzTopic)); + if (hSzApp) GlobalDeleteAtom(hSzApp); + if (hSzTopic) GlobalDeleteAtom(hSzTopic); } return 0; } - case WM_DDE_EXECUTE: /* posted message */ + case WM_DDE_EXECUTE: /* posted message */ { HGLOBAL hCommand; TCHAR *pszCommand; DDEACK ack; memset(&ack, 0, sizeof(ack)); - if(UnpackDDElParam(msg,lParam,NULL,(PUINT_PTR)&hCommand)) { + if (UnpackDDElParam(msg, lParam, NULL, (PUINT_PTR)&hCommand)) { /* ANSI execute command can't happen for shell */ - if(IsWindowUnicode((HWND)wParam)) { + if (IsWindowUnicode((HWND)wParam)) { pszCommand = (TCHAR*)GlobalLock(hCommand); - if(pszCommand!=NULL) { - TCHAR *pszAction,*pszArg; - pszAction=GetExecuteParam(&pszCommand); - pszArg=GetExecuteParam(&pszCommand); - if(pszArg!=NULL) { + if (pszCommand != NULL) { + TCHAR *pszAction = GetExecuteParam(&pszCommand); + TCHAR *pszArg = GetExecuteParam(&pszCommand); + if (pszArg != NULL) { /* we are inside miranda here, we make it async so the shell does * not timeout regardless what the plugins try to do. */ - if (!mir_tstrcmpi(pszAction,_T("file"))) - CallFunctionAsync(FileActionAsync,pszArg); - else if (!mir_tstrcmpi(pszAction,_T("url"))) - CallFunctionAsync(UrlActionAsync,pszArg); + if (!mir_tstrcmpi(pszAction, _T("file"))) + CallFunctionAsync(FileActionAsync, pszArg); + else if (!mir_tstrcmpi(pszAction, _T("url"))) + CallFunctionAsync(UrlActionAsync, pszArg); } GlobalUnlock(hCommand); } - } - - lParam=ReuseDDElParam(lParam,msg,WM_DDE_ACK,*(PUINT)&ack,(UINT)hCommand); - if (!PostMessage((HWND)wParam,WM_DDE_ACK,(WPARAM)hwnd,lParam)) { + + lParam = ReuseDDElParam(lParam, msg, WM_DDE_ACK, *(PUINT)&ack, (UINT_PTR)hCommand); + if (!PostMessage((HWND)wParam, WM_DDE_ACK, (WPARAM)hwnd, lParam)) { GlobalFree(hCommand); - FreeDDElParam(WM_DDE_ACK,lParam); + FreeDDElParam(WM_DDE_ACK, lParam); } } - return 0; } - case WM_DDE_TERMINATE: - PostMessage((HWND)wParam,msg,(WPARAM)hwnd,0); /* ack reply */ - return 0; - case WM_DDE_REQUEST: - case WM_DDE_ADVISE: - case WM_DDE_UNADVISE: - case WM_DDE_POKE: + return 0; + + case WM_DDE_TERMINATE: + PostMessage((HWND)wParam, msg, (WPARAM)hwnd, 0); /* ack reply */ + return 0; + + case WM_DDE_REQUEST: + case WM_DDE_ADVISE: + case WM_DDE_UNADVISE: + case WM_DDE_POKE: /* fail safely for those to avoid memory leak in lParam */ { ATOM hSzItem; DDEACK ack; memset(&ack, 0, sizeof(ack)); - if(UnpackDDElParam(msg,lParam,NULL,(PUINT_PTR)&hSzItem)) { - lParam=ReuseDDElParam(lParam,msg,WM_DDE_ACK,*(PUINT)&ack,(UINT)hSzItem); - if (!PostMessage((HWND)wParam,WM_DDE_ACK,(WPARAM)hwnd,lParam)) { - if(hSzItem) GlobalDeleteAtom(hSzItem); - FreeDDElParam(WM_DDE_ACK,lParam); + if (UnpackDDElParam(msg, lParam, NULL, (PUINT_PTR)&hSzItem)) { + lParam = ReuseDDElParam(lParam, msg, WM_DDE_ACK, *(PUINT)&ack, (UINT)hSzItem); + if (!PostMessage((HWND)wParam, WM_DDE_ACK, (WPARAM)hwnd, lParam)) { + if (hSzItem) GlobalDeleteAtom(hSzItem); + FreeDDElParam(WM_DDE_ACK, lParam); } } return 0; } } - return DefWindowProc(hwnd,msg,wParam,lParam); + return DefWindowProc(hwnd, msg, wParam, lParam); } // CloseHandle() the return value static HANDLE StartupMainProcess(TCHAR *pszDatabasePath) { - TCHAR *p,szPath[MAX_PATH]; + TCHAR *p, szPath[MAX_PATH]; /* we are inside RunDll32 here */ - if (!GetModuleFileName(hInst,szPath,_countof(szPath))) return NULL; - p=_tcsrchr(szPath,_T('\\')); - if(p!=NULL) { *p=0; p=_tcsrchr(szPath,_T('\\')); } - if(p==NULL) return NULL; - mir_tstrcpy(++p,_T("miranda32.exe")); + if (!GetModuleFileName(hInst, szPath, _countof(szPath))) return NULL; + p = _tcsrchr(szPath, _T('\\')); + if (p != NULL) { *p = 0; p = _tcsrchr(szPath, _T('\\')); } + if (p == NULL) return NULL; + mir_tstrcpy(++p, _T("miranda32.exe")); /* inherit startup data from RunDll32 process */ STARTUPINFO si; GetStartupInfo(&si); PROCESS_INFORMATION pi; - if (!CreateProcess(szPath,pszDatabasePath,NULL,NULL,TRUE,GetPriorityClass(GetCurrentProcess()),NULL,NULL,&si,&pi)) + if (!CreateProcess(szPath, pszDatabasePath, NULL, NULL, TRUE, GetPriorityClass(GetCurrentProcess()), NULL, NULL, &si, &pi)) return NULL; CloseHandle(pi.hThread); return pi.hProcess; @@ -189,31 +190,31 @@ static HANDLE StartupMainProcess(TCHAR *pszDatabasePath) extern "C" { #endif -// entry point for RunDll32, this is also WaitForDDEW -__declspec(dllexport) void CALLBACK WaitForDDE(HWND,HINSTANCE,TCHAR *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