OSDN Git Service

IniOptionsMgr.cpp: The value of the m_serializing variable was not initialized
[winmerge-jp/winmerge-jp.git] / ArchiveSupport / Merge7z / tools.cpp
1 /* tools.cpp: Supplementary classes and functions for Merge7z
2  * Copyright (c) 2003 Jochen Tucht
3  *
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.
8  *
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.
13  *
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.
17  *
18
19 Please mind 2. a) of the GNU General Public License, and log your changes below.
20
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
26 */
27
28 #include "stdafx.h"
29 #include "tools.h"
30
31 /**
32  * @brief Construct and throw a Complain object containing an error message.
33  */
34 Complain::Complain(LPCTSTR format, ...)
35 {
36         wvsprintf(msg, format, (va_list)(&format + 1));
37         throw this;
38 }
39
40 Complain::Complain(DWORD dwError, LPCTSTR pszContext, HMODULE hContext)
41 {
42         LPTSTR pszMessage = msg;
43         if (pszContext)
44         {
45                 pszMessage += wsprintf(pszMessage, _T("%.500s"), pszContext);
46                 if (hContext)
47                 {
48                         *pszMessage++ = _T('@');
49                         int cch = ::GetModuleFileName(hContext, pszMessage, 500);
50                         if (cch == 0)
51                         {
52                                 cch = wsprintf(pszMessage, _T("%p"), hContext);
53                         }
54                         pszMessage += cch;
55                 }
56                 *pszMessage++ = _T(':');
57                 *pszMessage++ = _T('\n');
58         }
59         FormatMessage
60         (
61                 FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,
62                 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
63                 pszMessage, 500, NULL
64         );
65         throw this;
66 }
67
68 /**
69  * @brief Report error to user. To be called from within catch block.
70  */
71 int Complain::Alert(HWND hwndParent, UINT flags)
72 {
73         return MessageBox(hwndParent, msg, 0, flags);
74 }
75
76 /**
77  * @brief Complain that some DLL failed to CreateObject() something.
78  */
79 void ComplainCreateObject(HMODULE handle, LPCTSTR name)
80 {
81         TCHAR szContext[800];
82         LPTSTR pszContext = szContext + wsprintf(szContext, _T("%.100s@"), name);
83         ::GetModuleFileName(handle, pszContext, 500);
84         Complain(RPC_S_INTERFACE_NOT_FOUND, szContext);
85
86
87 /**
88  * @brief Release interface until ref count reaches 0.
89  *
90  * Very bad practice in general, but helps avoiding resource leaks
91  * due to inaccurate ref counting.
92  */
93 void NTAPI Release(IUnknown *punk)
94 {
95         while (punk)
96         {       
97                 ULONG Release = punk->Release();
98                 if (Release == 0)
99                 {
100                         punk = 0;
101                 }
102         }
103 }