https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7014cf04b1a03540457cd…
commit 7014cf04b1a03540457cd61678cd517b523eee7f
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Sun Jan 23 00:59:12 2022 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Sun Jan 23 00:59:12 2022 +0900
[ATL][MSPAINT] Add ATLTRACE and fix assertion failures (#4299)
- Implement ATLTRACE and AtlTrace in atlbase.h.
- Fix assertion failures in mspaint.
CORE-17969, CORE-18012
---
base/applications/mspaint/history.cpp | 14 +-
base/applications/mspaint/imgarea.cpp | 10 +-
base/applications/mspaint/mouse.cpp | 2 +-
base/applications/mspaint/palettemodel.cpp | 9 +-
base/applications/mspaint/precomp.h | 9 +
base/applications/mspaint/scrollbox.cpp | 14 +-
base/applications/mspaint/selection.cpp | 2 +-
base/applications/mspaint/textedit.cpp | 8 +-
base/applications/mspaint/toolsmodel.cpp | 11 +-
base/applications/mspaint/winproc.cpp | 62 +++---
sdk/lib/atl/atlbase.h | 2 +-
sdk/lib/atl/atltrace.h | 293 +++++++++++++++++++++++++++++
12 files changed, 380 insertions(+), 56 deletions(-)
diff --git a/base/applications/mspaint/history.cpp
b/base/applications/mspaint/history.cpp
index 1a5cd8966a8..7aa36fab4dc 100644
--- a/base/applications/mspaint/history.cpp
+++ b/base/applications/mspaint/history.cpp
@@ -14,12 +14,14 @@
void ImageModel::NotifyDimensionsChanged()
{
- imageArea.SendMessage(WM_IMAGEMODELDIMENSIONSCHANGED);
+ if (imageArea.IsWindow())
+ imageArea.SendMessage(WM_IMAGEMODELDIMENSIONSCHANGED);
}
void ImageModel::NotifyImageChanged()
{
- imageArea.SendMessage(WM_IMAGEMODELIMAGECHANGED);
+ if (imageArea.IsWindow())
+ imageArea.SendMessage(WM_IMAGEMODELIMAGECHANGED);
}
ImageModel::ImageModel()
@@ -44,7 +46,7 @@ ImageModel::ImageModel()
void ImageModel::CopyPrevious()
{
- DPRINT("%s: %d\n", __FUNCTION__, currInd);
+ ATLTRACE("%s: %d\n", __FUNCTION__, currInd);
DeleteObject(hBms[(currInd + 1) % HISTORYSIZE]);
hBms[(currInd + 1) % HISTORYSIZE] = CopyDIBImage(hBms[currInd]);
currInd = (currInd + 1) % HISTORYSIZE;
@@ -57,7 +59,7 @@ void ImageModel::CopyPrevious()
void ImageModel::Undo()
{
- DPRINT("%s: %d\n", __FUNCTION__, undoSteps);
+ ATLTRACE("%s: %d\n", __FUNCTION__, undoSteps);
if (undoSteps > 0)
{
int oldWidth = GetWidth();
@@ -76,7 +78,7 @@ void ImageModel::Undo()
void ImageModel::Redo()
{
- DPRINT("%s: %d\n", __FUNCTION__, redoSteps);
+ ATLTRACE("%s: %d\n", __FUNCTION__, redoSteps);
if (redoSteps > 0)
{
int oldWidth = GetWidth();
@@ -95,7 +97,7 @@ void ImageModel::Redo()
void ImageModel::ResetToPrevious()
{
- DPRINT("%s: %d\n", __FUNCTION__, currInd);
+ ATLTRACE("%s: %d\n", __FUNCTION__, currInd);
DeleteObject(hBms[currInd]);
hBms[currInd] = CopyDIBImage(hBms[(currInd + HISTORYSIZE - 1) % HISTORYSIZE]);
SelectObject(hDrawingDC, hBms[currInd]);
diff --git a/base/applications/mspaint/imgarea.cpp
b/base/applications/mspaint/imgarea.cpp
index cfa9a84d8d3..0cb2f8de2ab 100644
--- a/base/applications/mspaint/imgarea.cpp
+++ b/base/applications/mspaint/imgarea.cpp
@@ -68,6 +68,8 @@ void CImgAreaWindow::drawZoomFrame(int mouseX, int mouseY)
LRESULT CImgAreaWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
+ if (!IsWindow() || !sizeboxLeftTop.IsWindow())
+ return 0;
int imgXRes = imageModel.GetWidth();
int imgYRes = imageModel.GetHeight();
sizeboxLeftTop.MoveWindow(
@@ -105,7 +107,7 @@ LRESULT CImgAreaWindow::OnEraseBkGnd(UINT nMsg, WPARAM wParam, LPARAM
lParam, BO
HDC hdc = (HDC)wParam;
if (toolsModel.GetActiveTool() == TOOL_TEXT &&
!toolsModel.IsBackgroundTransparent() &&
- textEditWindow.IsWindowVisible())
+ ::IsWindowVisible(textEditWindow))
{
// Do clipping
HWND hChild = textEditWindow;
@@ -143,11 +145,11 @@ LRESULT CImgAreaWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& b
DeleteObject(SelectObject(hdc, oldPen));
}
EndPaint(&ps);
- if (selectionWindow.IsWindowVisible())
+ if (selectionWindow.IsWindow())
selectionWindow.Invalidate(FALSE);
- if (miniature.IsWindowVisible())
+ if (miniature.IsWindow())
miniature.Invalidate(FALSE);
- if (textEditWindow.IsWindowVisible())
+ if (textEditWindow.IsWindow())
textEditWindow.Invalidate(FALSE);
return 0;
}
diff --git a/base/applications/mspaint/mouse.cpp b/base/applications/mspaint/mouse.cpp
index 16a6500e9d1..b442d0c9daf 100644
--- a/base/applications/mspaint/mouse.cpp
+++ b/base/applications/mspaint/mouse.cpp
@@ -394,7 +394,7 @@ struct TextTool : ToolBase
{
imageModel.ResetToPrevious();
- BOOL bTextBoxShown = textEditWindow.IsWindowVisible();
+ BOOL bTextBoxShown = ::IsWindowVisible(textEditWindow);
if (bTextBoxShown && textEditWindow.GetWindowTextLength() > 0)
{
CString szText;
diff --git a/base/applications/mspaint/palettemodel.cpp
b/base/applications/mspaint/palettemodel.cpp
index 1f5dd899be6..c91899bd982 100644
--- a/base/applications/mspaint/palettemodel.cpp
+++ b/base/applications/mspaint/palettemodel.cpp
@@ -95,13 +95,16 @@ void PaletteModel::SetBgColor(COLORREF newColor)
void PaletteModel::NotifyColorChanged()
{
- paletteWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
- selectionWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
+ if (paletteWindow.IsWindow())
+ paletteWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
+ if (selectionWindow.IsWindow())
+ selectionWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
if (textEditWindow.IsWindow())
textEditWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED);
}
void PaletteModel::NotifyPaletteChanged()
{
- paletteWindow.SendMessage(WM_PALETTEMODELPALETTECHANGED);
+ if (paletteWindow.IsWindow())
+ paletteWindow.SendMessage(WM_PALETTEMODELPALETTECHANGED);
}
diff --git a/base/applications/mspaint/precomp.h b/base/applications/mspaint/precomp.h
index 1f27501432f..df5b929bd82 100644
--- a/base/applications/mspaint/precomp.h
+++ b/base/applications/mspaint/precomp.h
@@ -1,6 +1,15 @@
#ifndef _MSPAINT_H
#define _MSPAINT_H
+#ifdef NDEBUG
+ #undef DBG
+ #undef _DEBUG
+#endif
+
+#if DBG && !defined(_DEBUG)
+ #define _DEBUG
+#endif
+
#include <stdarg.h>
#include <windef.h>
diff --git a/base/applications/mspaint/scrollbox.cpp
b/base/applications/mspaint/scrollbox.cpp
index d2be15f8f18..c05dffd5ec9 100644
--- a/base/applications/mspaint/scrollbox.cpp
+++ b/base/applications/mspaint/scrollbox.cpp
@@ -61,7 +61,8 @@ UpdateScrollbox()
scrollboxWindow.GetWindowRect(&tempRect);
sizeScrollBox = CSize(tempRect.Width(), tempRect.Height());
- imageArea.GetClientRect(&tempRect);
+ if (imageArea.IsWindow())
+ imageArea.GetClientRect(&tempRect);
sizeImageArea = CSize(tempRect.Width(), tempRect.Height());
sizeImageArea += CSize(GRIP_SIZE * 2, GRIP_SIZE * 2);
@@ -87,14 +88,17 @@ UpdateScrollbox()
si.nPage = sizeScrollBox.cy;
scrollboxWindow.SetScrollInfo(SB_VERT, &si);
- scrlClientWindow.MoveWindow(-scrollboxWindow.GetScrollPos(SB_HORZ),
- -scrollboxWindow.GetScrollPos(SB_VERT),
- sizeImageArea.cx, sizeImageArea.cy, TRUE);
+ if (scrlClientWindow.IsWindow())
+ {
+ scrlClientWindow.MoveWindow(
+ -scrollboxWindow.GetScrollPos(SB_HORZ),
-scrollboxWindow.GetScrollPos(SB_VERT),
+ sizeImageArea.cx, sizeImageArea.cy, TRUE);
+ }
}
LRESULT CScrollboxWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
- if (m_hWnd == scrollboxWindow.m_hWnd)
+ if (m_hWnd && m_hWnd == scrollboxWindow.m_hWnd)
{
UpdateScrollbox();
}
diff --git a/base/applications/mspaint/selection.cpp
b/base/applications/mspaint/selection.cpp
index c2c32880f97..74083505bc2 100644
--- a/base/applications/mspaint/selection.cpp
+++ b/base/applications/mspaint/selection.cpp
@@ -57,7 +57,7 @@ ColorKeyedMaskBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int
nHeight,
void
ForceRefreshSelectionContents()
{
- if (selectionWindow.IsWindowVisible())
+ if (::IsWindowVisible(selectionWindow))
{
selectionWindow.SendMessage(WM_LBUTTONDOWN, 0, MAKELPARAM(0, 0));
selectionWindow.SendMessage(WM_MOUSEMOVE, 0, MAKELPARAM(0, 0));
diff --git a/base/applications/mspaint/textedit.cpp
b/base/applications/mspaint/textedit.cpp
index 792633a55e7..80f87682e32 100644
--- a/base/applications/mspaint/textedit.cpp
+++ b/base/applications/mspaint/textedit.cpp
@@ -300,12 +300,12 @@ HWND CTextEditWindow::Create(HWND hwndParent)
const DWORD style = ES_LEFT | ES_MULTILINE | ES_WANTRETURN | ES_AUTOVSCROLL |
WS_CHILD | WS_THICKFRAME;
- m_hWnd = ::CreateWindowEx(0, WC_EDIT, NULL, style, 0, 0, 0, 0,
- hwndParent, NULL, hProgInstance, NULL);
- if (m_hWnd)
+ HWND hwnd = ::CreateWindowEx(0, WC_EDIT, NULL, style, 0, 0, 0, 0,
+ hwndParent, NULL, hProgInstance, NULL);
+ if (hwnd)
{
#undef SubclassWindow // Don't use this macro
- SubclassWindow(m_hWnd);
+ SubclassWindow(hwnd);
UpdateFont();
diff --git a/base/applications/mspaint/toolsmodel.cpp
b/base/applications/mspaint/toolsmodel.cpp
index 021df46d336..8811cf087ff 100644
--- a/base/applications/mspaint/toolsmodel.cpp
+++ b/base/applications/mspaint/toolsmodel.cpp
@@ -159,13 +159,14 @@ void ToolsModel::SetZoom(int nZoom)
void ToolsModel::NotifyToolChanged()
{
- toolBoxContainer.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
- toolSettingsWindow.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
-
+ if (toolBoxContainer.IsWindow())
+ toolBoxContainer.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
+ if (toolSettingsWindow.IsWindow())
+ toolSettingsWindow.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
if (fontsDialog.IsWindow())
fontsDialog.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
-
- textEditWindow.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
+ if (textEditWindow.IsWindow())
+ textEditWindow.SendMessage(WM_TOOLSMODELTOOLCHANGED, m_activeTool);
}
void ToolsModel::NotifyToolSettingsChanged()
diff --git a/base/applications/mspaint/winproc.cpp
b/base/applications/mspaint/winproc.cpp
index a0af103f080..9105d85115e 100644
--- a/base/applications/mspaint/winproc.cpp
+++ b/base/applications/mspaint/winproc.cpp
@@ -51,7 +51,7 @@ void CMainWindow::alignChildrenToMainWindow()
RECT clientRect;
GetClientRect(&clientRect);
- if (toolBoxContainer.IsWindowVisible())
+ if (::IsWindowVisible(toolBoxContainer))
{
x = 56;
w = clientRect.right - 56;
@@ -61,7 +61,7 @@ void CMainWindow::alignChildrenToMainWindow()
x = 0;
w = clientRect.right;
}
- if (paletteWindow.IsWindowVisible())
+ if (::IsWindowVisible(paletteWindow))
{
y = 49;
h = clientRect.bottom - 49;
@@ -73,13 +73,18 @@ void CMainWindow::alignChildrenToMainWindow()
}
RECT statusBarRect0;
- SendMessage(hStatusBar, SB_GETRECT, 0, (LPARAM)&statusBarRect0);
int statusBarBorders[3];
- SendMessage(hStatusBar, SB_GETBORDERS, 0, (LPARAM)&statusBarBorders);
+ if (::IsWindow(hStatusBar))
+ {
+ ::SendMessage(hStatusBar, SB_GETRECT, 0, (LPARAM)&statusBarRect0);
+ ::SendMessage(hStatusBar, SB_GETBORDERS, 0, (LPARAM)&statusBarBorders);
+ }
int statusBarHeight = statusBarRect0.bottom - statusBarRect0.top +
statusBarBorders[1];
- scrollboxWindow.MoveWindow(x, y, w, ::IsWindowVisible(hStatusBar) ? h -
statusBarHeight : h, TRUE);
- paletteWindow.MoveWindow(x, 9, 255, 32, TRUE);
+ if (scrollboxWindow.IsWindow())
+ scrollboxWindow.MoveWindow(x, y, w, ::IsWindowVisible(hStatusBar) ? h -
statusBarHeight : h, TRUE);
+ if (paletteWindow.IsWindow())
+ paletteWindow.MoveWindow(x, 9, 255, 32, TRUE);
}
void CMainWindow::saveImage(BOOL overwrite)
@@ -268,7 +273,9 @@ LRESULT CMainWindow::OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam,
BOOL& bHan
LRESULT CMainWindow::OnInitMenuPopup(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
HMENU menu = GetMenu();
- BOOL trueSelection = (selectionWindow.IsWindowVisible() &&
((toolsModel.GetActiveTool() == TOOL_FREESEL) || (toolsModel.GetActiveTool() ==
TOOL_RECTSEL)));
+ BOOL trueSelection =
+ (::IsWindowVisible(selectionWindow) &&
+ ((toolsModel.GetActiveTool() == TOOL_FREESEL) || (toolsModel.GetActiveTool() ==
TOOL_RECTSEL)));
switch (lParam)
{
case 0: /* File menu */
@@ -320,17 +327,17 @@ LRESULT CMainWindow::OnInitMenuPopup(UINT nMsg, WPARAM wParam,
LPARAM lParam, BO
CloseClipboard();
break;
case 2: /* View menu */
- CheckMenuItem(menu, IDM_VIEWTOOLBOX,
CHECKED_IF(toolBoxContainer.IsWindowVisible()));
- CheckMenuItem(menu, IDM_VIEWCOLORPALETTE,
CHECKED_IF(paletteWindow.IsWindowVisible()));
- CheckMenuItem(menu, IDM_VIEWSTATUSBAR,
CHECKED_IF(::IsWindowVisible(hStatusBar)));
- CheckMenuItem(menu, IDM_FORMATICONBAR,
CHECKED_IF(fontsDialog.IsWindowVisible()));
- EnableMenuItem(menu, IDM_FORMATICONBAR,
ENABLED_IF(toolsModel.GetActiveTool() == TOOL_TEXT));
+ CheckMenuItem(menu, IDM_VIEWTOOLBOX,
CHECKED_IF(::IsWindowVisible(toolBoxContainer)));
+ CheckMenuItem(menu, IDM_VIEWCOLORPALETTE,
CHECKED_IF(::IsWindowVisible(paletteWindow)));
+ CheckMenuItem(menu, IDM_VIEWSTATUSBAR,
CHECKED_IF(::IsWindowVisible(hStatusBar)));
+ CheckMenuItem(menu, IDM_FORMATICONBAR,
CHECKED_IF(::IsWindowVisible(fontsDialog)));
+ EnableMenuItem(menu, IDM_FORMATICONBAR, ENABLED_IF(toolsModel.GetActiveTool()
== TOOL_TEXT));
- CheckMenuItem(menu, IDM_VIEWSHOWGRID, CHECKED_IF(showGrid));
- CheckMenuItem(menu, IDM_VIEWSHOWMINIATURE, CHECKED_IF(showMiniature));
+ CheckMenuItem(menu, IDM_VIEWSHOWGRID, CHECKED_IF(showGrid));
+ CheckMenuItem(menu, IDM_VIEWSHOWMINIATURE, CHECKED_IF(showMiniature));
break;
case 3: /* Image menu */
- EnableMenuItem(menu, IDM_IMAGECROP,
ENABLED_IF(selectionWindow.IsWindowVisible()));
+ EnableMenuItem(menu, IDM_IMAGECROP,
ENABLED_IF(::IsWindowVisible(selectionWindow)));
CheckMenuItem(menu, IDM_IMAGEDRAWOPAQUE,
CHECKED_IF(!toolsModel.IsBackgroundTransparent()));
break;
}
@@ -351,8 +358,11 @@ LRESULT CMainWindow::OnInitMenuPopup(UINT nMsg, WPARAM wParam, LPARAM
lParam, BO
LRESULT CMainWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
int test[] = { LOWORD(lParam) - 260, LOWORD(lParam) - 140, LOWORD(lParam) - 20 };
- SendMessage(hStatusBar, WM_SIZE, wParam, lParam);
- SendMessage(hStatusBar, SB_SETPARTS, 3, (LPARAM)&test);
+ if (::IsWindow(hStatusBar))
+ {
+ ::SendMessage(hStatusBar, WM_SIZE, wParam, lParam);
+ ::SendMessage(hStatusBar, SB_SETPARTS, 3, (LPARAM)&test);
+ }
alignChildrenToMainWindow();
Invalidate(TRUE);
return 0;
@@ -519,13 +529,13 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& bH
break;
}
case IDM_EDITUNDO:
- if (toolsModel.GetActiveTool() == TOOL_TEXT &&
textEditWindow.IsWindowVisible())
+ if (toolsModel.GetActiveTool() == TOOL_TEXT &&
::IsWindowVisible(textEditWindow))
break;
imageModel.Undo();
imageArea.Invalidate(FALSE);
break;
case IDM_EDITREDO:
- if (toolsModel.GetActiveTool() == TOOL_TEXT &&
textEditWindow.IsWindowVisible())
+ if (toolsModel.GetActiveTool() == TOOL_TEXT &&
::IsWindowVisible(textEditWindow))
break;
imageModel.Redo();
imageArea.Invalidate(FALSE);
@@ -558,7 +568,7 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& bH
}
case IDM_EDITSELECTALL:
{
- if (toolsModel.GetActiveTool() == TOOL_TEXT &&
textEditWindow.IsWindowVisible())
+ if (toolsModel.GetActiveTool() == TOOL_TEXT &&
::IsWindowVisible(textEditWindow))
{
textEditWindow.SendMessage(EM_SETSEL, 0, -1);
break;
@@ -608,13 +618,13 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& bH
switch (mirrorRotateDialog.DoModal(mainWindow.m_hWnd))
{
case 1: /* flip horizontally */
- if (selectionWindow.IsWindowVisible())
+ if (::IsWindowVisible(selectionWindow))
selectionModel.FlipHorizontally();
else
imageModel.FlipHorizontally();
break;
case 2: /* flip vertically */
- if (selectionWindow.IsWindowVisible())
+ if (::IsWindowVisible(selectionWindow))
selectionModel.FlipVertically();
else
imageModel.FlipVertically();
@@ -622,7 +632,7 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& bH
case 3: /* rotate 90 degrees */
break;
case 4: /* rotate 180 degrees */
- if (selectionWindow.IsWindowVisible())
+ if (::IsWindowVisible(selectionWindow))
selectionModel.RotateNTimes90Degrees(2);
else
imageModel.RotateNTimes90Degrees(2);
@@ -656,11 +666,11 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& bH
break;
case IDM_VIEWTOOLBOX:
- toolBoxContainer.ShowWindow(toolBoxContainer.IsWindowVisible() ? SW_HIDE :
SW_SHOW);
+ toolBoxContainer.ShowWindow(::IsWindowVisible(toolBoxContainer) ? SW_HIDE :
SW_SHOW);
alignChildrenToMainWindow();
break;
case IDM_VIEWCOLORPALETTE:
- paletteWindow.ShowWindow(paletteWindow.IsWindowVisible() ? SW_HIDE :
SW_SHOW);
+ paletteWindow.ShowWindow(::IsWindowVisible(paletteWindow) ? SW_HIDE :
SW_SHOW);
alignChildrenToMainWindow();
break;
case IDM_VIEWSTATUSBAR:
@@ -674,7 +684,7 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& bH
{
fontsDialog.Create(mainWindow);
}
- registrySettings.ShowTextTool = !fontsDialog.IsWindowVisible();
+ registrySettings.ShowTextTool = !::IsWindowVisible(fontsDialog);
fontsDialog.ShowWindow(registrySettings.ShowTextTool ? SW_SHOW :
SW_HIDE);
fontsDialog.SendMessage(DM_REPOSITION, 0, 0);
}
diff --git a/sdk/lib/atl/atlbase.h b/sdk/lib/atl/atlbase.h
index 502d7b1ad44..a9408bb01a4 100644
--- a/sdk/lib/atl/atlbase.h
+++ b/sdk/lib/atl/atlbase.h
@@ -26,6 +26,7 @@
#include "atlcomcli.h"
#include "atlalloc.h"
#include "atlexcept.h"
+#include "atltrace.h"
#include "comcat.h"
#include "tchar.h"
@@ -1856,7 +1857,6 @@ inline HRESULT WINAPI AtlComModuleRevokeClassObjects(_ATL_COM_MODULE
*module)
return S_OK;
}
-
}; // namespace ATL
#ifndef _ATL_NO_AUTOMATIC_NAMESPACE
diff --git a/sdk/lib/atl/atltrace.h b/sdk/lib/atl/atltrace.h
new file mode 100644
index 00000000000..6230af9f1fc
--- /dev/null
+++ b/sdk/lib/atl/atltrace.h
@@ -0,0 +1,293 @@
+/*
+ * PROJECT: ReactOS ATL
+ * LICENSE: LGPL-2.0-or-later (
https://spdx.org/licenses/LGPL-2.0-or-later)
+ * PURPOSE: Providing ATLTRACE macro
+ * COPYRIGHT: Copyright 2022 Katayama Hirofumi MZ
<katayama.hirofumi.mz(a)gmail.com>
+ */
+
+#pragma once
+
+#include "atldef.h"
+
+#if DBG // FIXME: We should use _DEBUG instead of DBG. CORE-17505
+
+#include <stdio.h>
+#include <crtdbg.h>
+
+extern "C"
+{
+// FIXME: Enabling _DEBUG at top level causes assertion failures... CORE-17505
+int __cdecl _CrtDbgReport(int reportType, const char *filename, int linenumber, const
char *moduleName, const char *format, ...);
+int __cdecl _CrtDbgReportW(int reportType, const wchar_t *filename, int linenumber, const
wchar_t *moduleName, const wchar_t *format, ...);
+}
+
+namespace ATL
+{
+
+template <UINT t_category = (1 << 19), UINT t_level = 0>
+class CTraceCategoryEx
+{
+public:
+ enum
+ {
+ TraceGeneral = (1 << 0),
+ TraceCom = (1 << 1),
+ TraceQI = (1 << 2),
+ TraceRegistrar = (1 << 3),
+ TraceRefcount = (1 << 4),
+ TraceWindowing = (1 << 5),
+ TraceControls = (1 << 6),
+ TraceHosting = (1 << 7),
+ TraceDBClient = (1 << 8),
+ TraceDBProvider = (1 << 9),
+ TraceSnapin = (1 << 10),
+ TraceNotImpl = (1 << 11),
+ TraceAllocation = (1 << 12),
+ TraceException = (1 << 13),
+ TraceTime = (1 << 14),
+ TraceCache = (1 << 15),
+ TraceStencil = (1 << 16),
+ TraceString = (1 << 17),
+ TraceMap = (1 << 18),
+ TraceUtil = (1 << 19),
+ TraceSecurity = (1 << 20),
+ TraceSync = (1 << 21),
+ TraceISAPI = (1 << 22),
+ TraceUser = TraceUtil
+ };
+
+ CTraceCategoryEx(LPCTSTR name = NULL) : m_name(name)
+ {
+ }
+
+ static UINT GetLevel() { return t_level; }
+ static UINT GetCategory() { return t_category; }
+ operator UINT() const { return GetCategory(); }
+ LPCTSTR GetCategoryName() const { return m_name; }
+
+protected:
+ LPCTSTR m_name;
+};
+
+class CTraceCategory : public CTraceCategoryEx<>
+{
+ CTraceCategory(LPCTSTR name = NULL) : CTraceCategoryEx<>(name)
+ {
+ }
+};
+
+#define DEFINE_TRACE_CATEGORY(name, cat) extern const DECLSPEC_SELECTANY
CTraceCategoryEx<cat, 0> name(TEXT(#name))
+DEFINE_TRACE_CATEGORY(atlTraceGeneral, CTraceCategoryEx<>::TraceGeneral);
+DEFINE_TRACE_CATEGORY(atlTraceCOM, CTraceCategoryEx<>::TraceCom);
+DEFINE_TRACE_CATEGORY(atlTraceQI, CTraceCategoryEx<>::TraceQI);
+DEFINE_TRACE_CATEGORY(atlTraceRegistrar, CTraceCategoryEx<>::TraceRegistrar);
+DEFINE_TRACE_CATEGORY(atlTraceRefcount, CTraceCategoryEx<>::TraceRefcount);
+DEFINE_TRACE_CATEGORY(atlTraceWindowing, CTraceCategoryEx<>::TraceWindowing);
+DEFINE_TRACE_CATEGORY(atlTraceControls, CTraceCategoryEx<>::TraceControls);
+DEFINE_TRACE_CATEGORY(atlTraceHosting, CTraceCategoryEx<>::TraceHosting);
+DEFINE_TRACE_CATEGORY(atlTraceDBClient, CTraceCategoryEx<>::TraceDBClient);
+DEFINE_TRACE_CATEGORY(atlTraceDBProvider, CTraceCategoryEx<>::TraceDBProvider);
+DEFINE_TRACE_CATEGORY(atlTraceSnapin, CTraceCategoryEx<>::TraceSnapin);
+DEFINE_TRACE_CATEGORY(atlTraceNotImpl, CTraceCategoryEx<>::TraceNotImpl);
+DEFINE_TRACE_CATEGORY(atlTraceAllocation, CTraceCategoryEx<>::TraceAllocation);
+DEFINE_TRACE_CATEGORY(atlTraceException, CTraceCategoryEx<>::TraceException);
+DEFINE_TRACE_CATEGORY(atlTraceTime, CTraceCategoryEx<>::TraceTime);
+DEFINE_TRACE_CATEGORY(atlTraceCache, CTraceCategoryEx<>::TraceCache);
+DEFINE_TRACE_CATEGORY(atlTraceStencil, CTraceCategoryEx<>::TraceStencil);
+DEFINE_TRACE_CATEGORY(atlTraceString, CTraceCategoryEx<>::TraceString);
+DEFINE_TRACE_CATEGORY(atlTraceMap, CTraceCategoryEx<>::TraceMap);
+DEFINE_TRACE_CATEGORY(atlTraceUtil, CTraceCategoryEx<>::TraceUtil);
+DEFINE_TRACE_CATEGORY(atlTraceSecurity, CTraceCategoryEx<>::TraceSecurity);
+DEFINE_TRACE_CATEGORY(atlTraceSync, CTraceCategoryEx<>::TraceSync);
+DEFINE_TRACE_CATEGORY(atlTraceISAPI, CTraceCategoryEx<>::TraceISAPI);
+#undef DEFINE_TRACE_CATEGORY
+
+struct CTraceCategoryEasy
+{
+ UINT m_category;
+ UINT m_level;
+ LPCTSTR m_name;
+
+ template <UINT t_category, UINT t_level>
+ CTraceCategoryEasy(const CTraceCategoryEx<t_category, t_level>& cat)
+ {
+ m_category = t_category;
+ m_level = t_level;
+ m_name = cat.GetCategoryName();
+ }
+
+ operator UINT() const { return m_category; }
+
+ BOOL IsGeneral() const
+ {
+ return lstrcmp(m_name, TEXT("atlTraceGeneral")) == 0;
+ }
+};
+
+struct CTrace
+{
+ enum
+ {
+ DefaultTraceLevel = 0,
+ DisableTracing = 0xFFFFFFFF,
+ EnableAllCategories = 0xFFFFFFFF
+ };
+
+ static UINT GetLevel() { return s_level; }
+ static UINT GetCategories() { return s_categories; }
+ static void SetLevel(UINT level) { s_level = level; }
+ static void SetCategories(UINT categories) { s_categories = categories; }
+
+ static bool IsTracingEnabled(UINT category, UINT level)
+ {
+ return (s_level != DisableTracing && s_level >= level &&
(s_categories & category));
+ }
+
+protected:
+ static UINT s_categories;
+ static UINT s_level;
+};
+
+DECLSPEC_SELECTANY UINT CTrace::s_categories = CTrace::EnableAllCategories;
+DECLSPEC_SELECTANY UINT CTrace::s_level = CTrace::DefaultTraceLevel;
+
+template <typename X_CHAR>
+inline VOID __stdcall
+AtlTraceV(_In_opt_z_ const X_CHAR * file,
+ _In_ INT line,
+ _In_ const CTraceCategoryEasy& cat,
+ _In_ UINT level,
+ _In_z_ _Printf_format_string_ PCSTR format,
+ _In_ va_list va)
+{
+ char szBuff[1024], szFile[MAX_PATH];
+ size_t cch = 0;
+ const BOOL bUnicode = (sizeof(TCHAR) == 2);
+
+ if (!CTrace::IsTracingEnabled(cat, level))
+ return;
+
+#ifdef _STRSAFE_H_INCLUDED_
+ StringCchPrintfA(szFile, _countof(szFile), ((sizeof(X_CHAR) == 2) ? "%ls" :
"%hs"), file);
+ if (!cat.IsGeneral())
+ {
+ StringCchPrintfA(szBuff, _countof(szBuff), (bUnicode ? "%ls - " :
"%hs - "), cat.m_name);
+ StringCchLengthA(szBuff, _countof(szBuff), &cch);
+ }
+ StringCchVPrintfA(&szBuff[cch], _countof(szBuff) - cch, format, va);
+#else
+ _snprintf(szFile, _countof(szFile), ((sizeof(X_CHAR) == 2) ? "%ls" :
"%hs"), file);
+ if (!cat.IsGeneral())
+ cch = _snprintf(szBuff, _countof(szBuff), (bUnicode ? "%ls - " :
"%hs - "), cat.m_name);
+ _vsnprintf(&szBuff[cch], _countof(szBuff) - cch, format, va);
+#endif
+
+ _CrtDbgReport(_CRT_WARN, szFile, line, NULL, "%hs", szBuff);
+}
+
+template <typename X_CHAR>
+inline VOID __stdcall
+AtlTraceV(_In_opt_z_ const X_CHAR * file,
+ _In_ INT line,
+ _In_ const CTraceCategoryEasy& cat,
+ _In_ UINT level,
+ _In_z_ _Printf_format_string_ PCWSTR format,
+ _In_ va_list va)
+{
+ WCHAR szBuff[1024], szFile[MAX_PATH];
+ size_t cch = 0;
+ const BOOL bUnicode = (sizeof(TCHAR) == 2);
+
+ if (!CTrace::IsTracingEnabled(cat, level))
+ return;
+
+#ifdef _STRSAFE_H_INCLUDED_
+ StringCchPrintfW(szFile, _countof(szFile), ((sizeof(X_CHAR) == 2) ? L"%ls"
: L"%hs"), file);
+ if (!cat.IsGeneral())
+ {
+ StringCchPrintfW(szBuff, _countof(szBuff), (bUnicode ? L"%ls - " :
L"%hs - "), cat.m_name);
+ StringCchLengthW(szBuff, _countof(szBuff), &cch);
+ }
+ StringCchVPrintfW(&szBuff[cch], _countof(szBuff) - cch, format, va);
+#else
+ _snwprintf(szFile, _countof(szFile), ((sizeof(X_CHAR) == 2) ? L"%ls" :
L"%hs"), file);
+ if (!cat.IsGeneral())
+ cch = _snwprintf(szBuff, _countof(szBuff), (bUnicode ? L"%ls - " :
L"%hs - "), cat.m_name);
+ _vsnwprintf(&szBuff[cch], _countof(szBuff) - cch, format, va);
+#endif
+
+ _CrtDbgReportW(_CRT_WARN, szFile, line, NULL, L"%ls", szBuff);
+}
+
+template <typename X_CHAR, typename Y_CHAR>
+inline VOID __cdecl
+AtlTraceEx(_In_opt_z_ const X_CHAR * file,
+ _In_ INT line,
+ _In_ const CTraceCategoryEasy& cat,
+ _In_ UINT level,
+ _In_z_ _Printf_format_string_ const Y_CHAR * format,
+ ...)
+{
+ va_list va;
+ va_start(va, format);
+ AtlTraceV(file, line, cat, level, format, va);
+ va_end(va);
+}
+
+template <typename X_CHAR, typename Y_CHAR>
+inline VOID __cdecl
+AtlTraceEx(_In_opt_z_ const X_CHAR *file,
+ _In_ INT line,
+ _In_z_ _Printf_format_string_ const Y_CHAR *format,
+ ...)
+{
+ va_list va;
+ va_start(va, format);
+ AtlTraceV(file, line, atlTraceGeneral, 0, format, va);
+ va_end(va);
+}
+
+inline VOID __stdcall
+AtlTraceEx(_In_opt_z_ PCTSTR file,
+ _In_ INT line,
+ _In_ DWORD value)
+{
+ AtlTraceEx(file, line, TEXT("%ld (0x%lX)\n"), value, value);
+}
+
+template <typename X_CHAR>
+inline VOID __cdecl
+AtlTrace(_In_z_ _Printf_format_string_ const X_CHAR *format, ...)
+{
+ va_list va;
+ va_start(va, format);
+ AtlTraceV(NULL, -1, atlTraceGeneral, 0, format, va);
+ va_end(va);
+}
+
+} // namespace ATL
+
+#endif // DBG
+
+#ifndef ATLTRACE
+ #if DBG // FIXME: We should use _DEBUG instead of DBG. CORE-17505
+ #define ATLTRACE(format, ...) ATL::AtlTraceEx(__FILE__, __LINE__, format,
##__VA_ARGS__)
+ #else
+ #define ATLTRACE(format, ...) ((void)0)
+ #endif
+#endif
+
+#define ATLTRACE2 ATLTRACE
+
+#if DBG // FIXME: We should use _DEBUG instead of DBG. CORE-17505
+ #define ATLTRACENOTIMPL(funcname) do { \
+ ATLTRACE(atlTraceNotImpl, 0, #funcname " is not implemented.\n"); \
+ return E_NOTIMPL; \
+ } while (0)
+#else
+ #define ATLTRACENOTIMPL(funcname) return E_NOTIMPL
+#endif
+
+#ifndef _ATL_NO_AUTOMATIC_NAMESPACE
+using namespace ATL;
+#endif //!_ATL_NO_AUTOMATIC_NAMESPACE