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.1 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 "guidutil.h"
  14. #include "stdio.h"
  15. #undef DPF_MODNAME
  16. #define DPF_MODNAME "DVStringFromGUID"
  17. HRESULT DVStringFromGUID(const GUID* lpguid, WCHAR* swzBuf, DWORD dwNumChars)
  18. {
  19. if (dwNumChars < GUID_STRING_LEN)
  20. {
  21. return E_FAIL;
  22. }
  23. swprintf(
  24. swzBuf,
  25. L"{%-08.8X-%-04.4X-%-04.4X-%02.2X%02.2X-%02.2X%02.2X%02.2X%02.2X%02.2X%02.2X}",
  26. lpguid->Data1,
  27. lpguid->Data2,
  28. lpguid->Data3,
  29. lpguid->Data4[0],
  30. lpguid->Data4[1],
  31. lpguid->Data4[2],
  32. lpguid->Data4[3],
  33. lpguid->Data4[4],
  34. lpguid->Data4[5],
  35. lpguid->Data4[6],
  36. lpguid->Data4[7] );
  37. return S_OK;
  38. }
  39. #undef DPF_MODNAME
  40. #define DPF_MODNAME "DVGUIDFromString"
  41. HRESULT DVGUIDFromString(const WCHAR* wszBuf, GUID* lpguid)
  42. {
  43. UINT aiTmp[10];
  44. if( swscanf( wszBuf, L"{%8X-%4X-%4X-%2X%2X-%2X%2X%2X%2X%2X%2X}",
  45. &lpguid->Data1,
  46. &aiTmp[0], &aiTmp[1],
  47. &aiTmp[2], &aiTmp[3],
  48. &aiTmp[4], &aiTmp[5],
  49. &aiTmp[6], &aiTmp[7],
  50. &aiTmp[8], &aiTmp[9] ) != 11 )
  51. {
  52. ZeroMemory(lpguid, sizeof(GUID));
  53. return FALSE;
  54. }
  55. else
  56. {
  57. lpguid->Data2 = (USHORT) aiTmp[0];
  58. lpguid->Data3 = (USHORT) aiTmp[1];
  59. lpguid->Data4[0] = (BYTE) aiTmp[2];
  60. lpguid->Data4[1] = (BYTE) aiTmp[3];
  61. lpguid->Data4[2] = (BYTE) aiTmp[4];
  62. lpguid->Data4[3] = (BYTE) aiTmp[5];
  63. lpguid->Data4[4] = (BYTE) aiTmp[6];
  64. lpguid->Data4[5] = (BYTE) aiTmp[7];
  65. lpguid->Data4[6] = (BYTE) aiTmp[8];
  66. lpguid->Data4[7] = (BYTE) aiTmp[9];
  67. return TRUE;
  68. }
  69. }