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.

119 lines
3.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993 - 1993.
  5. //
  6. // File: ccompapi.cxx
  7. //
  8. // Contents: common compobj API Worker routines used by com, stg, scm etc
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 31-Dec-93 ErikGav Chicago port
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <windows.h>
  18. #include <ole2sp.h>
  19. #include <ole2com.h>
  20. NAME_SEG(CompApi)
  21. ASSERTDATA
  22. static const BYTE GuidMap[] = { 3, 2, 1, 0, '-', 5, 4, '-', 7, 6, '-',
  23. 8, 9, '-', 10, 11, 12, 13, 14, 15 };
  24. static const WCHAR wszDigits[] = L"0123456789ABCDEF";
  25. //+-------------------------------------------------------------------------
  26. //
  27. // Function: wStringFromGUID2 (internal)
  28. //
  29. // Synopsis: converts GUID into {...} form without leading identifier;
  30. //
  31. // Arguments: [rguid] - the guid to convert
  32. // [lpszy] - buffer to hold the results
  33. // [cbMax] - sizeof the buffer
  34. //
  35. // Returns: amount of data copied to lpsz if successful
  36. // 0 if buffer too small.
  37. //
  38. //--------------------------------------------------------------------------
  39. INTERNAL_(int) wStringFromGUID2(REFGUID rguid, LPWSTR lpsz, int cbMax)
  40. {
  41. int i;
  42. LPWSTR p = lpsz;
  43. const BYTE * pBytes = (const BYTE *) &rguid;
  44. *p++ = L'{';
  45. for (i = 0; i < sizeof(GuidMap); i++)
  46. {
  47. if (GuidMap[i] == '-')
  48. {
  49. *p++ = L'-';
  50. }
  51. else
  52. {
  53. *p++ = wszDigits[ (pBytes[GuidMap[i]] & 0xF0) >> 4 ];
  54. *p++ = wszDigits[ (pBytes[GuidMap[i]] & 0x0F) ];
  55. }
  56. }
  57. *p++ = L'}';
  58. *p = L'\0';
  59. return GUIDSTR_MAX;
  60. }
  61. #ifdef _CHICAGO_
  62. static const CHAR szDigits[] = "0123456789ABCDEF";
  63. //+-------------------------------------------------------------------------
  64. //
  65. // Function: wStringFromGUID2A (internal)
  66. //
  67. // Synopsis: Ansi version of wStringFromGUID2 (for Win95 Optimizations)
  68. //
  69. // Arguments: [rguid] - the guid to convert
  70. // [lpszy] - buffer to hold the results
  71. // [cbMax] - sizeof the buffer
  72. //
  73. // Returns: amount of data copied to lpsz if successful
  74. // 0 if buffer too small.
  75. //
  76. //--------------------------------------------------------------------------
  77. INTERNAL_(int) wStringFromGUID2A(REFGUID rguid, LPSTR lpsz, int cbMax) // internal
  78. {
  79. int i;
  80. LPSTR p = lpsz;
  81. const BYTE * pBytes = (const BYTE *) &rguid;
  82. *p++ = '{';
  83. for (i = 0; i < sizeof(GuidMap); i++)
  84. {
  85. if (GuidMap[i] == '-')
  86. {
  87. *p++ = '-';
  88. }
  89. else
  90. {
  91. *p++ = szDigits[ (pBytes[GuidMap[i]] & 0xF0) >> 4 ];
  92. *p++ = szDigits[ (pBytes[GuidMap[i]] & 0x0F) ];
  93. }
  94. }
  95. *p++ = '}';
  96. *p = '\0';
  97. return GUIDSTR_MAX;
  98. }
  99. #endif
  100.