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.

99 lines
2.0 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. sc = UuidToString( &guid, &guidString );
  49. if ( sc == RPC_S_OK ) {
  50. guidBuffer = LocalAlloc( LMEM_FIXED, ( wcslen( guidString ) + 1 ) * sizeof( WCHAR ) );
  51. if ( guidBuffer != NULL )
  52. wcscpy( guidBuffer, guidString );
  53. }
  54. }
  55. //
  56. // if either UuidCreate or UuidToString fails, sc will reflect that
  57. // failure which should be set by this function. If LocalAlloc fails, it
  58. // will have called SetLastError and we want to propagate that value back
  59. // to the caller.
  60. //
  61. if ( sc != RPC_S_OK )
  62. SetLastError( sc );
  63. if ( guidString != NULL )
  64. {
  65. RpcStringFree( &guidString );
  66. } // if:
  67. return( guidBuffer );
  68. } // ClRtlMakeGuid