Added HWndCounter tool to count/debug window handle usage

Add DSO Framer errors to our error log
Commented out a debug console.writeline
This commit is contained in:
2017-05-26 18:31:23 +00:00
parent cd3d3f15eb
commit 1648de9f8d
3 changed files with 34 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Volian.Base.Library
{
@@ -223,4 +224,34 @@ namespace Volian.Base.Library
#endif
}
}
public static class HWndCounter
{
[DllImport("kernel32.dll")]
private static extern IntPtr GetCurrentProcess();
[DllImport("user32.dll")]
private static extern uint GetGuiResources(IntPtr hProcess, uint uiFlags);
private enum ResourceType
{
Gdi = 0,
User = 1
}
public static void GetWindowHandlesForCurrentProcess(IntPtr hWnd)
{
GetWindowHandlesForCurrentProcess(hWnd, "");
}
private static uint lastUserObject = 0;
public static void GetWindowHandlesForCurrentProcess(IntPtr hWnd, string str, params object[] objects)
{
IntPtr processHandle = GetCurrentProcess();
uint gdiObjects = GetGuiResources(processHandle, (uint)ResourceType.Gdi);
uint userObjects = GetGuiResources(processHandle, (uint)ResourceType.User);
if (lastUserObject != userObjects)
Console.WriteLine("winhandle count = {0} GDIObjs {1} UserObjs {2} dif {3} {4}", gdiObjects + userObjects, gdiObjects, userObjects,(int)userObjects - (int)lastUserObject, string.Format(str, objects));
lastUserObject = userObjects;
//return Convert.ToInt32(gdiObjects + userObjects);
}
}
}