1 /* tools.cpp: Supplementary classes and functions for Merge7z
2 * Copyright (c) 2003 Jochen Tucht
4 * License: This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 Please mind 2. a) of the GNU General Public License, and log your changes below.
21 DATE: BY: DESCRIPTION:
22 ========== ================== ================================================
23 2003-12-09 Jochen Tucht Created
24 2005-02-26 Jochen Tucht Changed as explained in revision.txt
25 2005-08-20 Jochen Tucht Remove unused EnumList
32 * @brief Construct and throw a Complain object containing an error message.
34 Complain::Complain(LPCTSTR format, ...)
36 wvsprintf(msg, format, (va_list)(&format + 1));
40 Complain::Complain(DWORD dwError, LPCTSTR pszContext, HMODULE hContext)
42 LPTSTR pszMessage = msg;
45 pszMessage += wsprintf(pszMessage, _T("%.500s"), pszContext);
48 *pszMessage++ = _T('@');
49 int cch = ::GetModuleFileName(hContext, pszMessage, 500);
52 cch = wsprintf(pszMessage, _T("%p"), hContext);
56 *pszMessage++ = _T(':');
57 *pszMessage++ = _T('\n');
61 FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,
62 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
69 * @brief Report error to user. To be called from within catch block.
71 int Complain::Alert(HWND hwndParent, UINT flags)
73 return MessageBox(hwndParent, msg, 0, flags);
77 * @brief Complain that some DLL failed to CreateObject() something.
79 void ComplainCreateObject(HMODULE handle, LPCTSTR name)
82 LPTSTR pszContext = szContext + wsprintf(szContext, _T("%.100s@"), name);
83 ::GetModuleFileName(handle, pszContext, 500);
84 Complain(RPC_S_INTERFACE_NOT_FOUND, szContext);
88 * @brief Release interface until ref count reaches 0.
90 * Very bad practice in general, but helps avoiding resource leaks
91 * due to inaccurate ref counting.
93 void NTAPI Release(IUnknown *punk)
97 ULONG Release = punk->Release();