From c076ace51ef9da1c34c485c655c6c008ea5a8e3a Mon Sep 17 00:00:00 2001 From: anders_k Date: Sun, 17 Jan 2021 21:59:56 +0000 Subject: [PATCH] Added FormatMessage lookup git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@7252 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/Makensisw/lookup.cpp | 45 +++++++++++++++++++++++++++++++---- Contrib/Makensisw/resource.rc | 2 +- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/Contrib/Makensisw/lookup.cpp b/Contrib/Makensisw/lookup.cpp index 27abfadb..94403c74 100644 --- a/Contrib/Makensisw/lookup.cpp +++ b/Contrib/Makensisw/lookup.cpp @@ -13,7 +13,7 @@ #include "makensisw.h" #include #include -#include +#include #include #include "utils.h" #include "resource.h" @@ -34,6 +34,7 @@ template static LPWSTR SmartStrTToW(T*Src, LPWSTR Dst, UINT cch) return (StrTToW(Src, Dst, cch), Dst); } +#define StrToSInt StrBase10ToSInt template static int WINAPI StrBase10ToSInt(const T*str) { unsigned int v = 0, neg = 0, c, i = 0, base = 10; @@ -42,8 +43,9 @@ template static int WINAPI StrBase10ToSInt(const T*str) return neg ? (int) v * -1 : v; } -template static int WINAPI PathParseIconLocationFallback(T*Path) +template static ULARGE_INTEGER WINAPI PathParseIconLocationEx(T*Path) { + ULARGE_INTEGER li; int idx = 0; SIZE_T i, comma = 0; for (i = 0; Path[i]; ++i) @@ -56,7 +58,13 @@ template static int WINAPI PathParseIconLocationFallback(T*Path) Path[comma] = T('\0'); idx = StrBase10ToSInt(Path + comma + 1); } - return idx; + return (li.HighPart = (UINT) comma, li.LowPart = idx, li); +} + +template static int WINAPI PathParseIconLocationFallback(T*Path) +{ + ULARGE_INTEGER li = PathParseIconLocationEx(Path); + return li.LowPart; } static HRESULT GetSpecialFolderPath(HWND hWnd, LPTSTR Buf, UINT csidl) @@ -142,8 +150,8 @@ static LSTATUS WINAPI RegLoadMUIStringFallbackW(HKEY hKey, LPCWSTR Name, LPWSTR return ERROR_NOT_SUPPORTED; } -enum { LM_SHGLN, LM_SHLIS, LM_RLMS, LM_PPIL }; -LPCSTR g_ModeLbl[] = { "Path:", "Path:", "Registry:", "Path:" }; +enum { LM_SHGLN, LM_SHLIS, LM_RLMS, LM_PPIL, LM_FMTMSG }; +LPCSTR g_ModeLbl[] = { "Path:", "Path:", "Registry:", "Path:", "[Path,]Number:" }; struct DIALOGDATA { HRESULT (WINAPI*SHGLN)(PCWSTR p, PWSTR m, UINT cch, int*rid); @@ -179,6 +187,7 @@ static INT_PTR CALLBACK LookupDlgProc(HWND hDlg, UINT Msg, WPARAM WParam, LPARAM if (g_SHLIS) AddComboStringWithData(pDD->hMode, "SHLoadIndirectString", LM_SHLIS); if (pDD->RLMS) AddComboStringWithData(pDD->hMode, "RegLoadMUIString", LM_RLMS); if (pDD->PPIL) AddComboStringWithData(pDD->hMode, "PathParseIconLocation", LM_PPIL); + AddComboStringWithData(pDD->hMode, "FormatMessage", LM_FMTMSG); SNDMSG(pDD->hExtra, EM_LIMITTEXT, COUNTOF(buf), 0); SNDMSG(pDD->hMode, CB_SETCURSEL, (SIZE_T) 0, 0), SNDMSG(hDlg, WM_COMMAND, MAKELONG(IDC_LUMODE, CBN_SELENDOK), (SIZE_T) pDD->hMode); return TRUE; @@ -214,6 +223,9 @@ static INT_PTR CALLBACK LookupDlgProc(HWND hDlg, UINT Msg, WPARAM WParam, LPARAM case LM_PPIL: extra = _T("%WINDIR%\\Explorer.exe,-101"); break; + case LM_FMTMSG: + extra = _T("wininet.dll,12005"); + break; } ShowWindow(pDD->hOutIco, SW_HIDE); SetWindowText(pDD->hExtra, extra); @@ -293,6 +305,29 @@ static INT_PTR CALLBACK LookupDlgProc(HWND hDlg, UINT Msg, WPARAM WParam, LPARAM if (!hIco) goto die_hr; } break; + case LM_FMTMSG: + { + UINT flags = FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS; + ULARGE_INTEGER li = PathParseIconLocationEx(buf); + LPCTSTR numstr = buf; + HMODULE hMod = 0; + if (li.HighPart) + { + numstr = buf + ++li.HighPart; + hMod = LoadLibraryEx(buf, 0, LOAD_LIBRARY_AS_DATAFILE), flags |= FORMAT_MESSAGE_FROM_HMODULE; + if (!hMod) goto badmsgmod; + } + hr = StrToSInt(numstr); + if (!FormatMessage(flags, hMod, hr, 0, buf, COUNTOF(buf), NULL)) badmsgmod: + { + hr = GetLastError(); + AppendText(pDD->hOutTxt, "(Could not find message) "); + goto die_hr; + } + if (hMod) FreeLibrary(hMod); + SetWindowText(pDD->hOutTxt, buf); + } + break; } break; } diff --git a/Contrib/Makensisw/resource.rc b/Contrib/Makensisw/resource.rc index 1c4108d4..b5798b0a 100644 --- a/Contrib/Makensisw/resource.rc +++ b/Contrib/Makensisw/resource.rc @@ -285,7 +285,7 @@ BEGIN CONTROL "", IDC_LUMODE, COMBOBOX, CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 16, 20, 268, 114 CONTROL "", IDC_LUEXTRALABEL, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 16, 38, 268, 10 CONTROL "", IDC_LUEXTRATEXT, EDIT, ES_LEFT | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 16, 50, 268, 14 - CONTROL "", IDC_LUOUTPUTTEXT, EDIT, ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 7, 80, 286, 60 + CONTROL "", IDC_LUOUTPUTTEXT, EDIT, ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 7, 80, 286, 60 END /////////////////////////////////////////////////////////////////////////////