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.

77 lines
2.7 KiB

  1. #ifndef __UTILS_H__
  2. #define __UTILS_H__
  3. #include <windows.h>
  4. #include <olectl.h>
  5. #include <shlwapi.h>
  6. // BUGBUG - remove and include wininet.h
  7. #include "autoprox.hxx"
  8. /********************************************************************************************/
  9. // ClassID and GUID helpers
  10. HRESULT GetScriptEngineClassIDFromName(LPCSTR pszLanguage,LPSTR pszBuff,UINT cBuffSize);
  11. /********************************************************************************************/
  12. // String Helper functions and macros
  13. // allocates a temporary buffer that will disappear when it goes out of scope
  14. // NOTE: be careful of that -- make sure you use the string in the same or
  15. // nested scope in which you created this buffer. people should not use this
  16. // class directly. use the macro(s) below.
  17. //
  18. class TempBuffer {
  19. public:
  20. TempBuffer(ULONG cBytes) {
  21. m_pBuf = (cBytes <= 120) ? (char *)&m_szTmpBuf : (new(char[cBytes]));
  22. m_fHeapAlloc = (cBytes > 120);
  23. }
  24. ~TempBuffer() {
  25. if (m_pBuf && m_fHeapAlloc) delete m_pBuf;
  26. }
  27. void *GetBuffer() {
  28. return m_pBuf;
  29. }
  30. private:
  31. void *m_pBuf;
  32. // we'll use this temp buffer for small cases.
  33. //
  34. char m_szTmpBuf[120];
  35. unsigned m_fHeapAlloc:1;
  36. };
  37. // given and ANSI String, copy it into a wide buffer.
  38. // be careful about scoping when using this macro!
  39. //
  40. // how to use the below two macros:
  41. //
  42. // ...
  43. // LPSTR pszA;
  44. // pszA = MyGetAnsiStringRoutine();
  45. // MAKE_WIDEPTR_FROMANSI(pwsz, pszA);
  46. // MyUseWideStringRoutine(pwsz);
  47. // ...
  48. //
  49. // similarily for MAKE_ANSIPTR_FROMWIDE. note that the first param does not
  50. // have to be declared, and no clean up must be done.
  51. //
  52. #define MAKE_WIDEPTR_FROMANSI(ptrname, ansistr) \
  53. long __l##ptrname = (lstrlen(ansistr) + 1) * sizeof(WCHAR); \
  54. TempBuffer __TempBuffer##ptrname(__l##ptrname); \
  55. MultiByteToWideChar(CP_ACP, 0, ansistr, -1, (LPWSTR)__TempBuffer##ptrname.GetBuffer(), __l##ptrname); \
  56. LPWSTR ptrname = (LPWSTR)__TempBuffer##ptrname.GetBuffer()
  57. #define MAKE_ANSIPTR_FROMWIDE(ptrname, widestr) \
  58. long __l##ptrname = (lstrlenW(widestr) + 1) * 2 * sizeof(char); \
  59. TempBuffer __TempBuffer##ptrname(__l##ptrname); \
  60. WideCharToMultiByte(CP_ACP, 0, widestr, -1, (LPSTR)__TempBuffer##ptrname.GetBuffer(), __l##ptrname, NULL, NULL); \
  61. LPSTR ptrname = (LPSTR)__TempBuffer##ptrname.GetBuffer()
  62. LPWSTR MakeWideStrFromAnsi( LPCSTR, BYTE bType);
  63. #define STR_BSTR 0
  64. #define STR_OLESTR 1
  65. #define BSTRFROMANSI(x) (BSTR)MakeWideStrFromAnsi((LPSTR)(x), STR_BSTR)
  66. #define OLESTRFROMANSI(x) (LPOLESTR)MakeWideStrFromAnsi((LPSTR)(x), STR_OLESTR)
  67. int ConvertAnsiDayToInt(LPSTR szday);
  68. #endif