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.

167 lines
4.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dpmsgobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "dxfile.h"
  14. #include "XFileSaveObj.h"
  15. #include "XFileDataObj.h"
  16. extern HRESULT BSTRtoGUID(LPGUID,BSTR);
  17. extern BSTR GUIDtoBSTR(LPGUID);
  18. C_dxj_DirectXFileSaveObject::C_dxj_DirectXFileSaveObject()
  19. {
  20. m_pXfileSave=NULL;
  21. }
  22. C_dxj_DirectXFileSaveObject::~C_dxj_DirectXFileSaveObject()
  23. {
  24. if (m_pXfileSave) m_pXfileSave->Release();
  25. }
  26. HRESULT C_dxj_DirectXFileSaveObject::create( IDirectXFileSaveObject *pSave, I_dxj_DirectXFileSave **ret)
  27. {
  28. HRESULT hr;
  29. if (!ret) return E_INVALIDARG;
  30. if (!pSave) return E_INVALIDARG;
  31. C_dxj_DirectXFileSaveObject *c=NULL;
  32. c=new CComObject<C_dxj_DirectXFileSaveObject>;
  33. if( c == NULL ) return E_OUTOFMEMORY;
  34. c->m_pXfileSave=pSave;
  35. pSave->AddRef();
  36. hr=c->QueryInterface(IID_I_dxj_DirectXFileSave, (void**)ret);
  37. return hr;
  38. }
  39. STDMETHODIMP C_dxj_DirectXFileSaveObject::SaveTemplates(
  40. /* [in] */ long count,
  41. SAFEARRAY __RPC_FAR * __RPC_FAR *templateGuids)
  42. {
  43. HRESULT hr;
  44. GUID *pGuids=NULL;
  45. GUID **ppGuids=NULL;
  46. if (count<=0) return E_INVALIDARG;
  47. if (!templateGuids) return E_INVALIDARG;
  48. if (!((SAFEARRAY*)*templateGuids)->pvData) return E_INVALIDARG;
  49. __try { pGuids=(GUID*)alloca(sizeof(GUID)*count);} __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  50. __try { ppGuids=(GUID**)alloca(sizeof(GUID*)*count);} __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  51. if (!pGuids) return E_OUTOFMEMORY;
  52. __try
  53. {
  54. for (long i=0;i<count;i++)
  55. {
  56. hr=BSTRtoGUID(&(pGuids[i]),((BSTR*)(((SAFEARRAY*)*templateGuids)->pvData))[i]);
  57. if FAILED(hr) return E_INVALIDARG;
  58. ppGuids[i]=&(pGuids[i]);
  59. }
  60. }
  61. __except(1,1)
  62. {
  63. return E_INVALIDARG;
  64. }
  65. hr=m_pXfileSave->SaveTemplates((DWORD)count,(const GUID **) ppGuids);
  66. return hr;
  67. }
  68. STDMETHODIMP C_dxj_DirectXFileSaveObject::CreateDataObject(
  69. /* [in] */ BSTR templateGuid,
  70. /* [in] */ BSTR name,
  71. /* [in] */ BSTR dataTypeGuid,
  72. /* [in] */ long bytecount,
  73. /* [in] */ void __RPC_FAR *data,
  74. /* [retval][out] */ I_dxj_DirectXFileData __RPC_FAR *__RPC_FAR *ret)
  75. {
  76. USES_CONVERSION;
  77. HRESULT hr;
  78. IDirectXFileData *pXFileData=NULL;
  79. GUID *lpGuidTemplate=NULL;
  80. GUID *lpGuidDataType=NULL;
  81. char *szName=NULL;
  82. //use lazy evaluation
  83. if ((templateGuid)&&(templateGuid[0]!=0))
  84. {
  85. __try { lpGuidTemplate=(GUID*)alloca(sizeof(GUID));} __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  86. ZeroMemory(lpGuidTemplate,sizeof(GUID));
  87. hr=BSTRtoGUID(lpGuidTemplate,templateGuid);
  88. if FAILED(hr) return hr;
  89. }
  90. if (!lpGuidTemplate) return E_INVALIDARG;
  91. //use lazy evaluation
  92. if ((name)&&(name[0]!=0))
  93. {
  94. __try { szName = W2T(name); } __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  95. }
  96. //use lazy evaluation
  97. if ((dataTypeGuid)&&(dataTypeGuid[0]!=0))
  98. {
  99. __try { lpGuidDataType=(GUID*)alloca(sizeof(GUID));} __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  100. ZeroMemory(lpGuidDataType,sizeof(GUID));
  101. hr=BSTRtoGUID(lpGuidDataType,dataTypeGuid);
  102. if FAILED(hr) return hr;
  103. }
  104. __try {
  105. hr=m_pXfileSave->CreateDataObject(*lpGuidTemplate,szName,lpGuidDataType,(DWORD)bytecount,data,&pXFileData);
  106. }
  107. __except (1,1)
  108. {
  109. return E_INVALIDARG;
  110. }
  111. if FAILED(hr) return hr;
  112. hr=C_dxj_DirectXFileDataObject::create(pXFileData,ret);
  113. return hr;
  114. }
  115. STDMETHODIMP C_dxj_DirectXFileSaveObject::SaveData(
  116. /* [in] */ I_dxj_DirectXFileData __RPC_FAR *dataObj)
  117. {
  118. HRESULT hr;
  119. if (!dataObj) return E_INVALIDARG;
  120. IDirectXFileData *pDataObj=NULL;
  121. dataObj->InternalGetObject((IUnknown**)&pDataObj);
  122. hr=m_pXfileSave->SaveData(pDataObj);
  123. return hr;
  124. }