Bug 1232181 - Add a few win resource helpers. r?aklotz
MozReview-Commit-ID: EN3GE8waLCz
--- a/xpcom/base/nsWindowsHelpers.h
+++ b/xpcom/base/nsWindowsHelpers.h
@@ -45,16 +45,88 @@ public:
{
if (aFD != Void()) {
RegCloseKey(aFD);
}
}
};
template<>
+class nsAutoRefTraits<HDC>
+{
+public:
+ typedef HDC RawRef;
+ static HDC Void()
+ {
+ return nullptr;
+ }
+
+ static void Release(RawRef aFD)
+ {
+ if (aFD != Void()) {
+ ::DeleteDC(aFD);
+ }
+ }
+};
+
+template<>
+class nsAutoRefTraits<HBRUSH>
+{
+public:
+ typedef HBRUSH RawRef;
+ static HBRUSH Void()
+ {
+ return nullptr;
+ }
+
+ static void Release(RawRef aFD)
+ {
+ if (aFD != Void()) {
+ ::DeleteObject(aFD);
+ }
+ }
+};
+
+template<>
+class nsAutoRefTraits<HRGN>
+{
+public:
+ typedef HRGN RawRef;
+ static HRGN Void()
+ {
+ return nullptr;
+ }
+
+ static void Release(RawRef aFD)
+ {
+ if (aFD != Void()) {
+ ::DeleteObject(aFD);
+ }
+ }
+};
+
+template<>
+class nsAutoRefTraits<HBITMAP>
+{
+public:
+ typedef HBITMAP RawRef;
+ static HBITMAP Void()
+ {
+ return nullptr;
+ }
+
+ static void Release(RawRef aFD)
+ {
+ if (aFD != Void()) {
+ ::DeleteObject(aFD);
+ }
+ }
+};
+
+template<>
class nsAutoRefTraits<SC_HANDLE>
{
public:
typedef SC_HANDLE RawRef;
static SC_HANDLE Void()
{
return nullptr;
}
@@ -135,16 +207,20 @@ public:
{
if (aDevMode != Void()) {
::HeapFree(::GetProcessHeap(), 0, aDevMode);
}
}
};
typedef nsAutoRef<HKEY> nsAutoRegKey;
+typedef nsAutoRef<HDC> nsAutoHDC;
+typedef nsAutoRef<HBRUSH> nsAutoBrush;
+typedef nsAutoRef<HRGN> nsAutoRegion;
+typedef nsAutoRef<HBITMAP> nsAutoBitmap;
typedef nsAutoRef<SC_HANDLE> nsAutoServiceHandle;
typedef nsAutoRef<HANDLE> nsAutoHandle;
typedef nsAutoRef<HMODULE> nsModuleHandle;
typedef nsAutoRef<DEVMODEW*> nsAutoDevMode;
namespace {
HMODULE inline