Source code of Windows XP (NT5)
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.

76 lines
2.0 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: guidutil.cpp
  6. * Content: Some GUID related utility functions
  7. *
  8. * History:
  9. * Date By Reason
  10. * ============
  11. * 08/19/99 pnewson created
  12. ***************************************************************************/
  13. #include "dncmni.h"
  14. #undef DPF_MODNAME
  15. #define DPF_MODNAME "DVStringFromGUID"
  16. HRESULT DVStringFromGUID(const GUID* lpguid, WCHAR* swzBuf, DWORD dwNumChars)
  17. {
  18. if (dwNumChars < GUID_STRING_LEN)
  19. {
  20. return E_FAIL;
  21. }
  22. swprintf(
  23. swzBuf,
  24. L"{%-08.8X-%-04.4X-%-04.4X-%02.2X%02.2X-%02.2X%02.2X%02.2X%02.2X%02.2X%02.2X}",
  25. lpguid->Data1,
  26. lpguid->Data2,
  27. lpguid->Data3,
  28. lpguid->Data4[0],
  29. lpguid->Data4[1],
  30. lpguid->Data4[2],
  31. lpguid->Data4[3],
  32. lpguid->Data4[4],
  33. lpguid->Data4[5],
  34. lpguid->Data4[6],
  35. lpguid->Data4[7] );
  36. return S_OK;
  37. }
  38. #undef DPF_MODNAME
  39. #define DPF_MODNAME "DVGUIDFromString"
  40. HRESULT DVGUIDFromString(const WCHAR* wszBuf, GUID* lpguid)
  41. {
  42. UINT aiTmp[10];
  43. if( swscanf( wszBuf, L"{%8X-%4X-%4X-%2X%2X-%2X%2X%2X%2X%2X%2X}",
  44. &lpguid->Data1,
  45. &aiTmp[0], &aiTmp[1],
  46. &aiTmp[2], &aiTmp[3],
  47. &aiTmp[4], &aiTmp[5],
  48. &aiTmp[6], &aiTmp[7],
  49. &aiTmp[8], &aiTmp[9] ) != 11 )
  50. {
  51. ZeroMemory(lpguid, sizeof(GUID));
  52. return E_FAIL;
  53. }
  54. else
  55. {
  56. lpguid->Data2 = (USHORT) aiTmp[0];
  57. lpguid->Data3 = (USHORT) aiTmp[1];
  58. lpguid->Data4[0] = (BYTE) aiTmp[2];
  59. lpguid->Data4[1] = (BYTE) aiTmp[3];
  60. lpguid->Data4[2] = (BYTE) aiTmp[4];
  61. lpguid->Data4[3] = (BYTE) aiTmp[5];
  62. lpguid->Data4[4] = (BYTE) aiTmp[6];
  63. lpguid->Data4[5] = (BYTE) aiTmp[7];
  64. lpguid->Data4[6] = (BYTE) aiTmp[8];
  65. lpguid->Data4[7] = (BYTE) aiTmp[9];
  66. return S_OK;
  67. }
  68. }