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.

98 lines
1.7 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. rpc.c
  5. Abstract:
  6. Handy utility functions for supporting RPC
  7. Author:
  8. John Vert (jvert) 2-Jan-1996
  9. Revision History:
  10. --*/
  11. #include "clusrtlp.h"
  12. #include "rpc.h"
  13. void __RPC_FAR * __RPC_API MIDL_user_allocate(size_t len)
  14. {
  15. return(LocalAlloc(LMEM_FIXED, len));
  16. }
  17. void __RPC_API MIDL_user_free(void __RPC_FAR * ptr)
  18. {
  19. LocalFree(ptr);
  20. }
  21. LPWSTR
  22. ClRtlMakeGuid(
  23. VOID
  24. )
  25. /*++
  26. Routine Description:
  27. Creates a new GUID in string form.
  28. Arguments:
  29. None.
  30. Return Value:
  31. A pointer to the GUID string if successful.
  32. NULL if unsuccessful.
  33. Notes:
  34. The storage for the GUID string must be freed by the caller.
  35. Sometimes, the GUID storage is copied to a buffer that is
  36. allocated using another allocator. At that point, the free
  37. routines can't tell where free method to call. Sometimes this
  38. causes a problem. To get around this problem, antoher buffer
  39. is allocated such that the free methods will always work.
  40. --*/
  41. {
  42. DWORD sc;
  43. UUID guid;
  44. LPWSTR guidString = NULL;
  45. LPWSTR guidBuffer = NULL;
  46. sc = UuidCreate( &guid );
  47. if ( ( sc != RPC_S_OK ) && ( sc != RPC_S_UUID_LOCAL_ONLY ) )
  48. goto Error;
  49. sc = UuidToString( &guid, &guidString );
  50. if ( sc != RPC_S_OK )
  51. goto Error;
  52. guidBuffer = LocalAlloc( LMEM_FIXED, ( wcslen( guidString ) + 1 ) * sizeof( WCHAR ) );
  53. if ( guidBuffer == NULL )
  54. goto Error;
  55. wcscpy( guidBuffer, guidString );
  56. goto Cleanup;
  57. Error:
  58. SetLastError( sc );
  59. Cleanup:
  60. if ( guidString != NULL )
  61. {
  62. RpcStringFree( &guidString );
  63. } // if:
  64. return( guidBuffer );
  65. } // ClRtlMakeGuid