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.

100 lines
3.4 KiB

  1. // **************************************************************************
  2. // Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved
  3. //
  4. // File: utillib.h
  5. //
  6. // Description:
  7. // Set of sample routines
  8. //
  9. // History:
  10. //
  11. // **************************************************************************
  12. #define MAXITOA 19
  13. #define FWPRINTF myFWPrintf
  14. #define CLASSPROP L"__CLASS"
  15. #define SERVERPROP L"__SERVER"
  16. #define PATHPROP L"__PATH"
  17. #define NAMESPACEPROP L"__NAMESPACE"
  18. #define SYSTEMCLASS L"__SystemClass"
  19. #define RELPATHPROP L"__RELPATH"
  20. #define NAMEPROP L"Name"
  21. #define CIMTYPEQUAL L"CIMTYPE"
  22. #define KEYQUAL L"key"
  23. #define SYSTEMPREFIX L"__"
  24. #define CVTFAILED L"WideCharToMultiByte failed\n"
  25. #define RELEASE(a) if (a) { (a)->Release(); (a)=NULL;}
  26. #define BLOCKSIZE (32 * sizeof(WCHAR))
  27. #define CVTBUFSIZE (309+40) /* # of digits in max. dp value + slop (this size stolen from cvt.h in c runtime library) */
  28. #define PAGESIZE 4096
  29. #define ERROR_MODE_PRINTFIELDS 0
  30. #define ERROR_MODE_PRINTMOF 1
  31. #define UNREFERENCED(x)
  32. #include <comdef.h>
  33. _COM_SMARTPTR_TYPEDEF(IEnumWbemClassObject, __uuidof(IEnumWbemClassObject));
  34. _COM_SMARTPTR_TYPEDEF(IWbemLocator, __uuidof(IWbemLocator));
  35. _COM_SMARTPTR_TYPEDEF(IWbemCallResult, __uuidof(IWbemCallResult));
  36. _COM_SMARTPTR_TYPEDEF(IWbemClassObject, __uuidof(IWbemClassObject));
  37. _COM_SMARTPTR_TYPEDEF(IWbemContext, __uuidof(IWbemContext));
  38. _COM_SMARTPTR_TYPEDEF(IWbemObjectAccess, __uuidof(IWbemObjectAccess));
  39. _COM_SMARTPTR_TYPEDEF(IWbemObjectSink, __uuidof(IWbemObjectSink));
  40. _COM_SMARTPTR_TYPEDEF(IWbemQualifierSet, __uuidof(IWbemQualifierSet));
  41. _COM_SMARTPTR_TYPEDEF(IWbemServices, __uuidof(IWbemServices));
  42. _COM_SMARTPTR_TYPEDEF(IWbemStatusCodeText, __uuidof(IWbemStatusCodeText));
  43. char *cvt(WCHAR *x, char **y);
  44. double difftime(struct _timeb finish, struct _timeb start);
  45. int myFWPrintf(FILE *f, WCHAR *fmt, ...);
  46. const WCHAR *TypeToString(VARIANT *p);
  47. const WCHAR *TypeToString(VARTYPE v);
  48. const WCHAR *TypeToString(CIMTYPE v);
  49. WCHAR *ValueToString(CIMTYPE dwType, VARIANT *pValue, WCHAR **pbuf, WCHAR *fnHandler(VARIANT *pv) = NULL);
  50. BSTR WbemErrorString(SCODE sc);
  51. void PrintErrorAndExit(char *pszFailureReason, SCODE sc, DWORD dwMode);
  52. void PrintErrorAndAsk(char *pszFailureReason, SCODE sc, DWORD dwMode);
  53. void PrintError(char *pszFailureReason, SCODE sc, DWORD dwMode);
  54. class MyString {
  55. private:
  56. WCHAR *pwszString;
  57. public:
  58. MyString::MyString() {pwszString = (WCHAR *)calloc(1, sizeof(WCHAR));}
  59. MyString::~MyString() {free(pwszString);}
  60. WCHAR *GetString() {return pwszString;}
  61. void Empty() {free(pwszString);pwszString = (WCHAR *)calloc(1, sizeof(WCHAR));}
  62. WCHAR *GetCloneString()
  63. {
  64. WCHAR *buf = NULL;
  65. if (pwszString)
  66. {
  67. buf = (WCHAR *)malloc((wcslen(pwszString) + 1) * sizeof(WCHAR));
  68. if (buf)
  69. wcscpy(buf, pwszString);
  70. }
  71. return buf;
  72. }
  73. const MyString& operator+=(const WCHAR *arg1)
  74. {
  75. size_t iHave;
  76. size_t iNeed;
  77. if (arg1)
  78. {
  79. iHave = wcslen(pwszString);
  80. iNeed = wcslen(arg1);
  81. WCHAR* pTmp = (WCHAR *)realloc(pwszString, (iHave + iNeed + 1) * sizeof(WCHAR));
  82. if (pTmp)
  83. {
  84. pwszString = pTmp;
  85. wcscat(&pwszString[iHave], arg1);
  86. }
  87. }
  88. return *this;
  89. }
  90. };