Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
5.6 KiB

  1. //=--------------------------------------------------------------------------=
  2. // Util.H
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995-1996 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // contains utilities that we will find useful.
  13. //
  14. #ifndef _UTIL_H_
  15. #include "Globals.H"
  16. //=--------------------------------------------------------------------------=
  17. // Misc Helper Routines
  18. //=--------------------------------------------------------------------------=
  19. //
  20. HWND GetParkingWindow(void);
  21. HINSTANCE GetResourceHandle(void);
  22. //=--------------------------------------------------------------------------=
  23. // miscellaneous [useful] numerical constants
  24. //=--------------------------------------------------------------------------=
  25. // the length of a guid once printed out with -'s, leading and trailing bracket,
  26. // plus 1 for NULL
  27. //
  28. #define GUID_STR_LEN 40
  29. //=--------------------------------------------------------------------------=
  30. // allocates a temporary buffer that will disappear when it goes out of scope
  31. // NOTE: be careful of that -- make sure you use the string in the same or
  32. // nested scope in which you created this buffer. people should not use this
  33. // class directly. use the macro(s) below.
  34. //
  35. class TempBuffer {
  36. public:
  37. TempBuffer(ULONG cBytes) {
  38. m_pBuf = (cBytes <= 120) ? &m_szTmpBuf : HeapAlloc(g_hHeap, 0, cBytes);
  39. m_fHeapAlloc = (cBytes > 120);
  40. }
  41. ~TempBuffer() {
  42. if (m_pBuf && m_fHeapAlloc) HeapFree(g_hHeap, 0, m_pBuf);
  43. }
  44. void *GetBuffer() {
  45. return m_pBuf;
  46. }
  47. private:
  48. void *m_pBuf;
  49. // we'll use this temp buffer for small cases.
  50. //
  51. char m_szTmpBuf[120];
  52. unsigned m_fHeapAlloc:1;
  53. };
  54. //=--------------------------------------------------------------------------=
  55. // string helpers.
  56. //
  57. // given and ANSI String, copy it into a wide buffer.
  58. // be careful about scoping when using this macro!
  59. //
  60. // how to use the below two macros:
  61. //
  62. // ...
  63. // LPSTR pszA;
  64. // pszA = MyGetAnsiStringRoutine();
  65. // MAKE_WIDEPTR_FROMANSI(pwsz, pszA);
  66. // MyUseWideStringRoutine(pwsz);
  67. // ...
  68. //
  69. // similarily for MAKE_ANSIPTR_FROMWIDE. note that the first param does not
  70. // have to be declared, and no clean up must be done.
  71. //
  72. #define MAKE_WIDEPTR_FROMANSI(ptrname, ansistr) \
  73. long __l##ptrname = (lstrlen(ansistr) + 1) * sizeof(WCHAR); \
  74. TempBuffer __TempBuffer##ptrname(__l##ptrname); \
  75. MultiByteToWideChar(CP_ACP, 0, ansistr, -1, (LPWSTR)__TempBuffer##ptrname.GetBuffer(), __l##ptrname); \
  76. LPWSTR ptrname = (LPWSTR)__TempBuffer##ptrname.GetBuffer()
  77. //
  78. // Note: allocate lstrlenW(widestr) * 2 because its possible for a UNICODE
  79. // character to map to 2 ansi characters this is a quick guarantee that enough
  80. // space will be allocated.
  81. //
  82. #define MAKE_ANSIPTR_FROMWIDE(ptrname, widestr) \
  83. long __l##ptrname = (lstrlenW(widestr) + 1) * 2 * sizeof(char); \
  84. TempBuffer __TempBuffer##ptrname(__l##ptrname); \
  85. WideCharToMultiByte(CP_ACP, 0, widestr, -1, (LPSTR)__TempBuffer##ptrname.GetBuffer(), __l##ptrname, NULL, NULL); \
  86. LPSTR ptrname = (LPSTR)__TempBuffer##ptrname.GetBuffer()
  87. #define STR_BSTR 0
  88. #define STR_OLESTR 1
  89. #define BSTRFROMANSI(x) (BSTR)MakeWideStrFromAnsi((LPSTR)(x), STR_BSTR)
  90. #define OLESTRFROMANSI(x) (LPOLESTR)MakeWideStrFromAnsi((LPSTR)(x), STR_OLESTR)
  91. #define BSTRFROMRESID(x) (BSTR)MakeWideStrFromResourceId(x, STR_BSTR)
  92. #define OLESTRFROMRESID(x) (LPOLESTR)MakeWideStrFromResourceId(x, STR_OLESTR)
  93. #define COPYOLESTR(x) (LPOLESTR)MakeWideStrFromWide(x, STR_OLESTR)
  94. #define COPYBSTR(x) (BSTR)MakeWideStrFromWide(x, STR_BSTR)
  95. LPWSTR MakeWideStrFromAnsi(LPSTR, BYTE bType);
  96. LPWSTR MakeWideStrFromResourceId(WORD, BYTE bType);
  97. LPWSTR MakeWideStrFromWide(LPWSTR, BYTE bType);
  98. // takes a GUID, and a pointer to a buffer, and places the string form of the
  99. // GUID in said buffer.
  100. //
  101. int StringFromGuidA(REFIID, LPSTR);
  102. //=--------------------------------------------------------------------------=
  103. // registry helpers.
  104. //
  105. // takes some information about an Automation Object, and places all the
  106. // relevant information about it in the registry.
  107. //
  108. BOOL RegSetMultipleValues(HKEY hkey, ...);
  109. BOOL RegisterUnknownObject(LPCSTR pszObjectName, REFCLSID riidObject);
  110. BOOL RegisterAutomationObject(LPCSTR pszLibName, LPCSTR pszObjectName, long lVersion, REFCLSID riidLibrary, REFCLSID riidObject);
  111. BOOL RegisterControlObject(LPCSTR pszLibName, LPCSTR pszObjectName, long lVersion, REFCLSID riidLibrary, REFCLSID riidObject, DWORD dwMiscStatus, WORD wToolboxBitmapId);
  112. BOOL UnregisterUnknownObject(REFCLSID riidObject);
  113. BOOL UnregisterAutomationObject(LPCSTR pszLibName, LPCSTR pszObjectName, long lVersion, REFCLSID riidObject);
  114. #define UnregisterControlObject UnregisterAutomationObject
  115. BOOL UnregisterTypeLibrary(REFCLSID riidLibrary);
  116. // deletes a key in the registr and all of it's subkeys
  117. //
  118. BOOL DeleteKeyAndSubKeys(HKEY hk, LPSTR pszSubKey);
  119. //=--------------------------------------------------------------------------=
  120. // conversion helpers.
  121. //
  122. void HiMetricToPixel(const SIZEL *pSizeInHiMetric, SIZEL *pSizeinPixels);
  123. void PixelToHiMetric(const SIZEL *pSizeInPixels, SIZEL *pSizeInHiMetric);
  124. #define _UTIL_H_
  125. #endif // _UTIL_H_
  126.