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.

106 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 1996, 1997 Microsoft Corporation
  3. Module Name:
  4. guidcnvt.cpp
  5. Abstract:
  6. Functionality in this module:
  7. Guid <-> String conversion
  8. Author:
  9. Matt Thomlinson (mattt) 1-May-97
  10. --*/
  11. #include <windows.h>
  12. #include <string.h>
  13. #include "pstdef.h"
  14. // crypto defs
  15. #include <sha.h>
  16. #include "unicode.h"
  17. #include "unicode5.h"
  18. #include "guidcnvt.h"
  19. // guid -> string conversion
  20. DWORD MyGuidToStringA(const GUID* pguid, CHAR rgsz[])
  21. {
  22. DWORD dwRet = (DWORD)PST_E_FAIL;
  23. LPSTR szTmp = NULL;
  24. if (RPC_S_OK != (dwRet =
  25. UuidToStringA(
  26. (UUID*)pguid,
  27. (unsigned char**) &szTmp)) )
  28. goto Ret;
  29. if (lstrlenA((LPSTR)szTmp) >= MAX_GUID_SZ_CHARS)
  30. {
  31. dwRet = (DWORD)PST_E_FAIL;
  32. goto Ret;
  33. }
  34. lstrcpyA(rgsz, szTmp);
  35. dwRet = PST_E_OK;
  36. Ret:
  37. if (szTmp)
  38. RpcStringFreeA((unsigned char**)&szTmp);
  39. return dwRet;
  40. }
  41. // string -> guid conversion
  42. DWORD MyGuidFromStringA(LPSTR sz, GUID* pguid)
  43. {
  44. DWORD dwRet = (DWORD)PST_E_FAIL;
  45. if (pguid == NULL)
  46. goto Ret;
  47. if (RPC_S_OK != (dwRet =
  48. UuidFromStringA(
  49. (unsigned char*)sz,
  50. (UUID*)pguid)) )
  51. goto Ret;
  52. dwRet = PST_E_OK;
  53. Ret:
  54. return dwRet;
  55. }
  56. // guid -> string conversion
  57. DWORD MyGuidToStringW(const GUID* pguid, WCHAR rgsz[])
  58. {
  59. RPC_STATUS rpcStatus;
  60. LPWSTR wszStringUUID;
  61. DWORD cchStringUUID;
  62. rpcStatus = UuidToStringW((UUID*)pguid, &wszStringUUID);
  63. if(rpcStatus != RPC_S_OK)
  64. return rpcStatus;
  65. cchStringUUID = lstrlenW(wszStringUUID);
  66. if (cchStringUUID >= MAX_GUID_SZ_CHARS)
  67. {
  68. RpcStringFreeW(&wszStringUUID);
  69. return (DWORD)PST_E_FAIL;
  70. }
  71. CopyMemory(rgsz, wszStringUUID, (cchStringUUID + 1) * sizeof(WCHAR));
  72. RpcStringFreeW(&wszStringUUID);
  73. return rpcStatus;
  74. }
  75. // string -> guid conversion
  76. DWORD MyGuidFromStringW(LPWSTR szW, GUID* pguid)
  77. {
  78. return UuidFromStringW(szW, pguid);
  79. }