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.

63 lines
1.4 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  5. //
  6. // File: util.cpp
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 7/8/1996 RaviR Created
  15. //
  16. //____________________________________________________________________________
  17. #include <objbase.h>
  18. #include <basetyps.h>
  19. #include "dbg.h"
  20. #include "cstr.h"
  21. #include <Atlbase.h>
  22. #include <winnls.h>
  23. //+---------------------------------------------------------------------------
  24. //
  25. // Function: GUIDToString
  26. // GUIDFromString
  27. //
  28. // Synopsis: Converts between GUID& and CStr
  29. //
  30. // Returns: FALSE for invalid string, or CMemoryException
  31. //
  32. //+---------------------------------------------------------------------------
  33. HRESULT GUIDToCStr(CStr& str, const GUID& guid)
  34. {
  35. LPOLESTR lpolestr = NULL;
  36. HRESULT hr = StringFromIID( guid, &lpolestr );
  37. if (FAILED(hr))
  38. {
  39. TRACE("GUIDToString error %ld\n", hr);
  40. return hr;
  41. }
  42. else
  43. {
  44. str = lpolestr;
  45. CoTaskMemFree(lpolestr);
  46. }
  47. return hr;
  48. }
  49. HRESULT GUIDFromCStr(const CStr& str, GUID* pguid)
  50. {
  51. USES_CONVERSION;
  52. HRESULT hr = IIDFromString( T2OLE( const_cast<LPTSTR>((LPCTSTR)str) ), pguid );
  53. if (FAILED(hr))
  54. {
  55. TRACE("GUIDFromString error %ld\n", hr);
  56. }
  57. return hr;
  58. }