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.

604 lines
23 KiB

  1. // Copyright (c) 1998-1999 Microsoft Corporation
  2. // Loader.h : Declaration of CLoader
  3. //
  4. // @doc EXTERNAL
  5. //
  6. #ifndef __CDMLOADER_H_
  7. #define __CDMLOADER_H_
  8. #include <windows.h>
  9. #define COM_NO_WINDOWS_H
  10. #include <objbase.h>
  11. #include "dmusici.h"
  12. #include "Alist.h"
  13. #include "riff.h"
  14. #include "ima.h"
  15. #include <mmreg.h>
  16. #include <stdio.h>
  17. #include "smartref.h"
  18. #include "..\shared\dmusicp.h"
  19. class CLoader;
  20. class CClass;
  21. #define FOURCC_RIFF_CACHE mmioFOURCC('D','M','L','C')
  22. #define FOURCC_LIST_CLASSLIST mmioFOURCC('c','l','s','l')
  23. #define FOURCC_CLASSHEADER mmioFOURCC('c','l','s','h')
  24. #define FOURCC_LIST_OBJLIST mmioFOURCC('o','b','j','l')
  25. #define FOURCC_OBJHEADER mmioFOURCC('o','b','j','h')
  26. // We need an older sized object descriptor for parameter validation.
  27. typedef struct _DMUS_OLDOBJECTDESC
  28. {
  29. DWORD dwSize; /* Size of this structure. */
  30. DWORD dwValidData; /* Flags indicating which fields below are valid. */
  31. GUID guidObject; /* Unique ID for this object. */
  32. GUID guidClass; /* GUID for the class of object. */
  33. FILETIME ftDate; /* Last edited date of object. */
  34. DMUS_VERSION vVersion; /* Version. */
  35. WCHAR wszName[DMUS_MAX_NAME]; /* Name of object. */
  36. WCHAR wszCategory[DMUS_MAX_CATEGORY]; /* Category for object (optional). */
  37. WCHAR wszFileName[DMUS_MAX_FILENAME]; /* File path. */
  38. LONGLONG llMemLength; /* Size of Memory data. */
  39. LPBYTE pbMemData; /* Memory pointer for data. */
  40. } DMUS_OLDOBJECTDESC;
  41. class CDescriptor
  42. {
  43. public:
  44. CDescriptor();
  45. ~CDescriptor();
  46. void Get(LPDMUS_OBJECTDESC pDesc);
  47. void Set(LPDMUS_OBJECTDESC pDesc);
  48. void Merge(CDescriptor * pDesc);
  49. void ClearName();
  50. void SetName(WCHAR *pwzName);
  51. void ClearCategory();
  52. void SetCategory(WCHAR *pwzCategory);
  53. void ClearFileName();
  54. HRESULT SetFileName(WCHAR *pwzFileName);
  55. void SetIStream(IStream *pIStream);
  56. void ClearIStream();
  57. void Copy(CDescriptor *pDesc);
  58. BOOL IsExtension(WCHAR *pwzExtension);
  59. public:
  60. LONGLONG m_llMemLength; // Memory size.
  61. DWORD m_dwValidData; // Flags indicating which of above is valid.
  62. GUID m_guidObject; // Unique ID for this object.
  63. GUID m_guidClass; // GUID for the class of object.
  64. FILETIME m_ftDate; // File date of object.
  65. DMUS_VERSION m_vVersion; // Version, as set by authoring tool.
  66. WCHAR * m_pwzName; // Name of object.
  67. WCHAR * m_pwzCategory; // Category for object (optional).
  68. WCHAR * m_pwzFileName; // File path.
  69. DWORD m_dwFileSize; // Size of file.
  70. BYTE * m_pbMemData; // Pointer to memory.
  71. IStream * m_pIStream; // Pointer to IStream object.
  72. LARGE_INTEGER m_liStartPosition; // Position in stream to start at.
  73. CRITICAL_SECTION m_CriticalSection; // Critical section for the descriptor's stream.
  74. BOOL m_fCSInitialized;
  75. };
  76. #define SCAN_CACHE 1 // Was found in cache file.
  77. #define SCAN_PRIOR 2 // Was in list prior to scanning.
  78. #define SCAN_PARSED 4 // Was parsed in the directory.
  79. #define SCAN_SEARCH 8 // Type of object we are searching for.
  80. const DWORD SCAN_GC = 1 << 12; // Object was cached while garbage collection was enabled.
  81. const DWORD SCAN_GC_MARK = 1 << 13; // Bit set during marking phase of CollectGarbage. Objects that remain unmarked are garbage.
  82. // Also used to detect cycles.
  83. class CObject : public AListItem
  84. {
  85. public:
  86. CObject(CClass *pClass);
  87. CObject(CClass *pClass, CDescriptor *pDesc);
  88. ~CObject();
  89. CObject * GetNext() {return(CObject *)AListItem::GetNext();};
  90. HRESULT Load();
  91. HRESULT Parse();
  92. HRESULT ParseFromFile();
  93. HRESULT ParseFromMemory();
  94. HRESULT ParseFromStream();
  95. HRESULT GC_Collectable();
  96. HRESULT GC_AddReference(CObject *pObject);
  97. HRESULT GC_RemoveReference(CObject *pObject);
  98. HRESULT GC_RemoveAndDuplicateInParentList();
  99. CDescriptor m_ObjectDesc;
  100. IDirectMusicObject * m_pIDMObject;
  101. DWORD m_dwScanBits;
  102. SmartRef::Vector<CObject*> * m_pvecReferences;
  103. private:
  104. CClass * m_pClass;
  105. };
  106. class CObjectList : public AList
  107. {
  108. public:
  109. CObject * GetHead() {return (CObject *)AList::GetHead();};
  110. CObject * RemoveHead() {return (CObject *)AList::RemoveHead();};
  111. void GC_Sweep(BOOL bOnlyScripts = FALSE);
  112. };
  113. class CClass : public AListItem
  114. {
  115. public:
  116. CClass( CLoader *pLoader );
  117. CClass( CLoader *pLoader, CDescriptor *pDesc );
  118. ~CClass();
  119. void ClearObjects(BOOL fKeepCache,WCHAR *pwzExtension);
  120. void RemoveObject(CObject* pRemoveObject);
  121. CClass * GetNext() {return(CClass *)AListItem::GetNext();};
  122. HRESULT GetPath(WCHAR *pwzPath); // Finds path.
  123. HRESULT FindObject(CDescriptor *pDesc,CObject **ppObject, CObject *NotThis = NULL);
  124. HRESULT EnumerateObjects(
  125. DWORD dwIndex,
  126. CDescriptor *pDesc) ;
  127. HRESULT SetSearchDirectory(WCHAR *pwzPath,BOOL fClear);
  128. HRESULT SearchDirectory(WCHAR *pwzFileExtension);
  129. HRESULT EnableCache(BOOL fEnable);
  130. HRESULT ClearCache(bool fClearStreams); // fClearStreams also clears the IStream members of all descriptors. It is used when shutting down the loader in Release.
  131. HRESULT SaveToCache(IRIFFStream *pRiff);
  132. HRESULT GetObject(CDescriptor *pDesc, CObject ** ppObject);
  133. void PreScan();
  134. void GC_Replace(CObject *pObject, CObject *pObjectReplacement);
  135. void GC_Sweep() { m_ObjectList.GC_Sweep(); }
  136. CDescriptor m_ClassDesc;
  137. CLoader * m_pLoader;
  138. BOOL m_fKeepObjects; // Hang onto objects after loading them.
  139. friend void GC_Report(CLoader *);
  140. private:
  141. CObjectList m_ObjectList;
  142. DWORD m_dwLastIndex; // For tracking enumeration.
  143. CObject * m_pLastObject; // Last object enumerated.
  144. BOOL m_fDirSearched; // Directory has been searched for files.
  145. };
  146. class CClassList : public AList
  147. {
  148. public:
  149. CClass * GetHead() {return (CClass *)AList::GetHead();};
  150. CClass * RemoveHead() {return (CClass *)AList::RemoveHead();};
  151. };
  152. class CLoader : public IDirectMusicLoader8, public IDirectMusicLoader8P, public IDirectMusicIMA
  153. {
  154. public:
  155. // IUnknown
  156. //
  157. virtual STDMETHODIMP QueryInterface(const IID &iid, void **ppv);
  158. virtual STDMETHODIMP_(ULONG) AddRef();
  159. virtual STDMETHODIMP_(ULONG) Release();
  160. // IDirectMusicLoader
  161. virtual STDMETHODIMP GetObject(LPDMUS_OBJECTDESC pDesc, REFIID, LPVOID FAR *) ;
  162. virtual STDMETHODIMP SetObject(LPDMUS_OBJECTDESC pDesc) ;
  163. virtual STDMETHODIMP SetSearchDirectory(REFGUID rguidClass, WCHAR *pwzPath, BOOL fClear) ;
  164. virtual STDMETHODIMP ScanDirectory(REFGUID rguidClass, WCHAR *pwzFileExtension, WCHAR *pwzScanFileName) ;
  165. virtual STDMETHODIMP CacheObject(IDirectMusicObject * pObject) ;
  166. virtual STDMETHODIMP ReleaseObject(IDirectMusicObject * pObject) ;
  167. virtual STDMETHODIMP ClearCache(REFGUID rguidClass) ;
  168. virtual STDMETHODIMP EnableCache(REFGUID rguidClass, BOOL fEnable) ;
  169. virtual STDMETHODIMP EnumObject(REFGUID rguidClass, DWORD dwIndex, LPDMUS_OBJECTDESC pDesc) ;
  170. // IDirectMusicLoader8
  171. virtual STDMETHODIMP_(void) CollectGarbage() ;
  172. virtual STDMETHODIMP ReleaseObjectByUnknown(IUnknown *pObject) ;
  173. virtual STDMETHODIMP GetDynamicallyReferencedObject(IDirectMusicObject *pSourceObject,
  174. LPDMUS_OBJECTDESC pDesc,
  175. REFIID riid,
  176. LPVOID FAR *ppv) ;
  177. virtual STDMETHODIMP ReportDynamicallyReferencedObject(IDirectMusicObject *pSourceObject,
  178. IUnknown *pReferencedObject);
  179. virtual STDMETHODIMP LoadObjectFromFile(REFGUID rguidClassID,
  180. REFIID iidInterfaceID,
  181. WCHAR *pwzFilePath,
  182. void ** ppObject) ;
  183. virtual ULONG STDMETHODCALLTYPE AddRefP(); // Private AddRef, for streams and scripts.
  184. virtual ULONG STDMETHODCALLTYPE ReleaseP(); // Private Release, for streams and scripts.
  185. // IDirectMusicIMA
  186. virtual STDMETHODIMP LegacyCaching( BOOL fEnable) ;
  187. CLoader();
  188. ~CLoader();
  189. HRESULT Init();
  190. HRESULT GetPath(WCHAR *pwzPath); // Finds path.
  191. void GC_UpdateForReleasedObject(CObject *pObject); // Used by ReleaseObject and CClass::ClearCache in removing objects from the cache.
  192. BOOL m_fIMA; // Support IMA parsing of ini files, etc.
  193. BOOL m_fKeepObjects; // Hang on to objects after loading them.
  194. friend void GC_Report(CLoader *);
  195. private:
  196. HRESULT LoadCacheFile(WCHAR *pwzCacheFileName);
  197. HRESULT SaveCacheFile(WCHAR *pwzCacheFileName);
  198. HRESULT GetClass(CDescriptor *pDesc, CClass **ppClass, BOOL fCreate);
  199. HRESULT ClearCacheInternal(REFGUID rguidClass, bool fClearStreams); // fClearStreams also clears the IStream members of all descriptors. It is used when shutting down the loader in Release.
  200. HRESULT FindObject(CDescriptor *pDesc, CClass **ppClass, CObject ** ppObject);
  201. HRESULT FindObject(IDirectMusicObject *pIDMObject, CObject ** ppObject);
  202. void GC_Mark(CObject *pObject);
  203. bool GC_HasCycle(CObject *pObject);
  204. // Recursive function used to implement GC_Mark and GC_HasCycle
  205. bool GC_TraverseHelper(CObject *pObject, CObject *pObjectToFind, bool fMark);
  206. CClassList m_ClassList; // Each type has its own list.
  207. WCHAR m_wzPath[DMUS_MAX_FILENAME]; // Search directory.
  208. BOOL m_fPathValid; // Search dir is valid.
  209. long m_cRef;
  210. long m_cPRef; // Private reference count.
  211. CRITICAL_SECTION m_CriticalSection; // Critical section to manage lists.
  212. BOOL m_fCSInitialized;
  213. CObject * m_pApplicationObject; // Object used to track references to objects in use by the application.
  214. CObject * m_pLoadedObjectContext; // Used to determine which object called GetObject. Initially m_pApplicationContext, but set and restored as a cascade of GetObject calls occurs between components.
  215. CObjectList m_ReleasedObjectList; // Holds objects that are released, but may still be referenced by other objects.
  216. // Debug-only functions used by GetObject to report load failures.
  217. // Frequently some file will fail to load because it depends on some other file
  218. // that is missing and this will print out trace statements helping the user
  219. // understand what's missing.
  220. #ifdef DBG
  221. void DebugTraceLoadFailure(CObject *pObject, HRESULT hrLoad);
  222. static void DebugTraceObject(DMUS_OBJECTDESC *pDesc);
  223. SmartRef::Vector<DMUS_OBJECTDESC> m_vecdescDebugTraceLoadFailure; // accumulates the failed sub-items
  224. #endif
  225. };
  226. /*
  227. @interface IDirectMusicGetLoader |
  228. If a stream supports the loader, it must provide an
  229. <i IDirectMusicGetLoader> interface so any object that is
  230. parsing the stream can use it to access the loader when
  231. it needs to load another object that is referenced by the
  232. file.
  233. @base public | IUnknown
  234. @meth HRESULT | GetLoader | Returns the loader.
  235. @xref <i IDirectMusicLoader>
  236. */
  237. class CFileStream : public IStream, public IDirectMusicGetLoader
  238. {
  239. public:
  240. // IUnknown
  241. //
  242. virtual STDMETHODIMP QueryInterface(const IID &iid, void **ppv);
  243. virtual STDMETHODIMP_(ULONG) AddRef();
  244. virtual STDMETHODIMP_(ULONG) Release();
  245. /* IStream methods */
  246. virtual STDMETHODIMP Read( void* pv, ULONG cb, ULONG* pcbRead );
  247. virtual STDMETHODIMP Write( const void* pv, ULONG cb, ULONG* pcbWritten );
  248. virtual STDMETHODIMP Seek( LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition );
  249. virtual STDMETHODIMP SetSize( ULARGE_INTEGER /*libNewSize*/ );
  250. virtual STDMETHODIMP CopyTo( IStream* /*pstm */, ULARGE_INTEGER /*cb*/,
  251. ULARGE_INTEGER* /*pcbRead*/,
  252. ULARGE_INTEGER* /*pcbWritten*/ );
  253. virtual STDMETHODIMP Commit( DWORD /*grfCommitFlags*/ );
  254. virtual STDMETHODIMP Revert();
  255. virtual STDMETHODIMP LockRegion( ULARGE_INTEGER /*libOffset*/, ULARGE_INTEGER /*cb*/,
  256. DWORD /*dwLockType*/ );
  257. virtual STDMETHODIMP UnlockRegion( ULARGE_INTEGER /*libOffset*/, ULARGE_INTEGER /*cb*/,
  258. DWORD /*dwLockType*/);
  259. virtual STDMETHODIMP Stat( STATSTG* /*pstatstg*/, DWORD /*grfStatFlag*/ );
  260. virtual STDMETHODIMP Clone( IStream** /*ppstm*/ );
  261. /* IDirectMusicGetLoader */
  262. virtual STDMETHODIMP GetLoader(IDirectMusicLoader ** ppLoader);
  263. CFileStream( CLoader *pLoader );
  264. ~CFileStream();
  265. HRESULT Open( WCHAR *lpFileName, DWORD dwDesiredAccess );
  266. HRESULT Close();
  267. private:
  268. LONG m_cRef; // object reference count
  269. WCHAR m_wszFileName[DMUS_MAX_FILENAME]; // Save name for cloning.
  270. #ifdef UNDER_CE
  271. HANDLE m_hFile;
  272. #else
  273. FILE* m_pFile; // file pointer
  274. #endif
  275. CLoader * m_pLoader;
  276. };
  277. class CMemStream : public IStream, public IDirectMusicGetLoader
  278. {
  279. public:
  280. // IUnknown
  281. //
  282. virtual STDMETHODIMP QueryInterface(const IID &iid, void **ppv);
  283. virtual STDMETHODIMP_(ULONG) AddRef();
  284. virtual STDMETHODIMP_(ULONG) Release();
  285. /* IStream methods */
  286. virtual STDMETHODIMP Read( void* pv, ULONG cb, ULONG* pcbRead );
  287. virtual STDMETHODIMP Write( const void* pv, ULONG cb, ULONG* pcbWritten );
  288. virtual STDMETHODIMP Seek( LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition );
  289. virtual STDMETHODIMP SetSize( ULARGE_INTEGER /*libNewSize*/ );
  290. virtual STDMETHODIMP CopyTo( IStream* /*pstm */, ULARGE_INTEGER /*cb*/,
  291. ULARGE_INTEGER* /*pcbRead*/,
  292. ULARGE_INTEGER* /*pcbWritten*/ );
  293. virtual STDMETHODIMP Commit( DWORD /*grfCommitFlags*/ );
  294. virtual STDMETHODIMP Revert();
  295. virtual STDMETHODIMP LockRegion( ULARGE_INTEGER /*libOffset*/, ULARGE_INTEGER /*cb*/,
  296. DWORD /*dwLockType*/ );
  297. virtual STDMETHODIMP UnlockRegion( ULARGE_INTEGER /*libOffset*/, ULARGE_INTEGER /*cb*/,
  298. DWORD /*dwLockType*/);
  299. virtual STDMETHODIMP Stat( STATSTG* /*pstatstg*/, DWORD /*grfStatFlag*/ );
  300. virtual STDMETHODIMP Clone( IStream** /*ppstm*/ );
  301. /* IDirectMusicGetLoader */
  302. virtual STDMETHODIMP GetLoader(IDirectMusicLoader ** ppLoader);
  303. CMemStream( CLoader *pLoader );
  304. CMemStream( CLoader *pLoader,
  305. LONGLONG llLength,
  306. LONGLONG llPosition,
  307. BYTE *pbData);
  308. ~CMemStream();
  309. HRESULT Open( BYTE *pbData, LONGLONG llLength );
  310. HRESULT Close();
  311. private:
  312. LONG m_cRef; // object reference count
  313. BYTE* m_pbData; // memory pointer
  314. LONGLONG m_llLength;
  315. LONGLONG m_llPosition; // Current file position.
  316. CLoader * m_pLoader;
  317. };
  318. class CStream : public IStream, public IDirectMusicGetLoader
  319. {
  320. public:
  321. // IUnknown
  322. //
  323. virtual STDMETHODIMP QueryInterface(const IID &iid, void **ppv);
  324. virtual STDMETHODIMP_(ULONG) AddRef();
  325. virtual STDMETHODIMP_(ULONG) Release();
  326. /* IStream methods */
  327. virtual STDMETHODIMP Read( void* pv, ULONG cb, ULONG* pcbRead );
  328. virtual STDMETHODIMP Write( const void* pv, ULONG cb, ULONG* pcbWritten );
  329. virtual STDMETHODIMP Seek( LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition );
  330. virtual STDMETHODIMP SetSize( ULARGE_INTEGER /*libNewSize*/ );
  331. virtual STDMETHODIMP CopyTo( IStream* /*pstm */, ULARGE_INTEGER /*cb*/,
  332. ULARGE_INTEGER* /*pcbRead*/,
  333. ULARGE_INTEGER* /*pcbWritten*/ );
  334. virtual STDMETHODIMP Commit( DWORD /*grfCommitFlags*/ );
  335. virtual STDMETHODIMP Revert();
  336. virtual STDMETHODIMP LockRegion( ULARGE_INTEGER /*libOffset*/, ULARGE_INTEGER /*cb*/,
  337. DWORD /*dwLockType*/ );
  338. virtual STDMETHODIMP UnlockRegion( ULARGE_INTEGER /*libOffset*/, ULARGE_INTEGER /*cb*/,
  339. DWORD /*dwLockType*/);
  340. virtual STDMETHODIMP Stat( STATSTG* /*pstatstg*/, DWORD /*grfStatFlag*/ );
  341. virtual STDMETHODIMP Clone( IStream** /*ppstm*/ );
  342. /* IDirectMusicGetLoader */
  343. virtual STDMETHODIMP GetLoader(IDirectMusicLoader ** ppLoader);
  344. CStream( CLoader *pLoader );
  345. CStream( CLoader *pLoader, IStream *pStream );
  346. ~CStream();
  347. HRESULT Open(IStream *pIStream,LARGE_INTEGER liStartPosition);
  348. HRESULT Close();
  349. private:
  350. LONG m_cRef; // object reference count
  351. IStream * m_pIStream;
  352. CLoader * m_pLoader;
  353. };
  354. // Class factory
  355. //
  356. class CLoaderFactory : public IClassFactory
  357. {
  358. public:
  359. // IUnknown
  360. //
  361. virtual STDMETHODIMP QueryInterface(const IID &iid, void **ppv);
  362. virtual STDMETHODIMP_(ULONG) AddRef();
  363. virtual STDMETHODIMP_(ULONG) Release();
  364. // Interface IClassFactory
  365. //
  366. virtual STDMETHODIMP CreateInstance(IUnknown* pUnknownOuter, const IID& iid, void** ppv);
  367. virtual STDMETHODIMP LockServer(BOOL bLock);
  368. // Constructor
  369. //
  370. CLoaderFactory();
  371. // Destructor
  372. ~CLoaderFactory();
  373. private:
  374. long m_cRef;
  375. };
  376. class CContainerFactory : public IClassFactory
  377. {
  378. public:
  379. // IUnknown
  380. //
  381. virtual STDMETHODIMP QueryInterface(const IID &iid, void **ppv);
  382. virtual STDMETHODIMP_(ULONG) AddRef();
  383. virtual STDMETHODIMP_(ULONG) Release();
  384. // Interface IClassFactory
  385. //
  386. virtual STDMETHODIMP CreateInstance(IUnknown* pUnknownOuter, const IID& iid, void** ppv);
  387. virtual STDMETHODIMP LockServer(BOOL bLock);
  388. // Constructor
  389. //
  390. CContainerFactory();
  391. // Destructor
  392. ~CContainerFactory();
  393. private:
  394. long m_cRef;
  395. };
  396. /*
  397. @interface IDirectMusicObject |
  398. All DirectMusic objects support the <i IDirectMusicObject>
  399. interface in order to
  400. work with the DirectMusic loader. In addition to
  401. providing a standard generic interface that the loader can
  402. communicate with, this provides a generic mechanism that
  403. allows an application to query an object for information
  404. about it, including Name, Guid, file path, version info,
  405. and more.
  406. If you are writing a DirectMusic compatible object, you
  407. must support <i IDirectMusicObject>, along with <i IPersistStream>,
  408. which is used in
  409. tandem with <i IDirectMusicObject> to load the object.
  410. @base public | IUnknown
  411. @meth HRESULT | GetDescriptor | Get the object's internal description, in <t DMUS_OBJECTDESC> format.
  412. @meth HRESULT | SetDescriptor | Set the object's internal description, in <t DMUS_OBJECTDESC> format.
  413. @meth HRESULT | ParseDescriptor | Parse into the supplied stream and find information about the file to store in <t DMUS_OBJECTDESC> format.
  414. @xref <t DMUS_OBJECTDESC>, <i IDirectMusicLoader>
  415. */
  416. #ifdef ONLYAUTODOCS
  417. /*
  418. @method:(EXTERNAL) HRESULT | IDirectMusicObject | GetDescriptor |
  419. Get the object's internal description.
  420. This method takes a <t DMUS_OBJECTDESC> structure and fills in everything
  421. it knows about itself. Depending on the implementation of the object and
  422. how it was loaded from a file, some or all of the standard
  423. parameters will be filled by <om IDirectMusicObject::GetDescriptor>.
  424. Be sure to check the flags in <e DMUS_OBJECTDESC.dwValidData> to understand
  425. which fields are valid.
  426. @rdesc Returns one of the following
  427. @flag S_OK | Success
  428. @ex The following example uses <om IDirectMusicObject::GetDescriptor> to
  429. read the name from a DirectMusic style: |
  430. IDirectMusicStyle *pStyle; // Style that was previously loaded.
  431. if (pStyle)
  432. {
  433. IDirectMusicObject *pIObject;
  434. DMUS_OBJECTDESC Desc; // Descriptor.
  435. if (SUCCEEDED(QueryInterface(IID_IDirectMusicObject,(void **) &pIObject);
  436. {
  437. if (SUCCEEDED(pIObject->GetDescriptor(&Desc))
  438. {
  439. if (Desc.dwValidData & DMUS_OBJ_NAME)
  440. {
  441. TRACE("Style name is %S\n",Desc.wszName);
  442. }
  443. }
  444. pIObject->Release();
  445. }
  446. }
  447. @xref <i IDirectMusicObject>, <om IDirectMusicObject::SetDescriptor>,
  448. <om IDirectMusicObject::ParseDescriptor>,<t DMUS_OBJECTDESC>, <i IDirectMusicLoader>
  449. */
  450. HRESULT CDMStyle::GetDescriptor(
  451. LPDMUS_OBJECTDESC pDesc) // @parm Descriptor to be filled with data about object.
  452. {
  453. return S_OK;
  454. }
  455. /*
  456. @method:(EXTERNAL) HRESULT | IDirectMusicObject | SetDescriptor |
  457. Set some or all fields of the object's internal description.
  458. This method takes a <t DMUS_OBJECTDESC> structure and copies the
  459. fields that are enabled with by a flag in
  460. <e DMUS_OBJECTDESC.dwValidData>.
  461. Fields that are not copied keep their previous values. For example,
  462. an object may already have its name and GUID stored internally.
  463. A call to its <om IDirectMusicObject::SetDescriptor> method with
  464. a new name and file path (DMUS_OBJ_NAME and DMUS_OBJ_FILENAME)
  465. would replace the name, give it a file name, and leave the
  466. GUID alone.
  467. This is primarily used by the loader when creating an object.
  468. However, it can be used by an application to rename an object.
  469. If the object is unable to set one or more fields, it sets the
  470. fields that it does support, clears the flags in <e DMUS_OBJECTDESC.dwValidData>
  471. that it does not support, and returns S_FALSE.
  472. If nothing else, an object should support DMUS_OBJ_NAME and DMUS_OBJ_OBJECT.
  473. @rdesc Returns one of the following
  474. @flag S_OK | Success
  475. @flag S_FALSE | Was unable to set some parameters. The <p pDesc>'s dwValidData
  476. field will contain only those flags that were successfully set.
  477. @xref <i IDirectMusicObject>, <om IDirectMusicObject::GetDescriptor>,
  478. <om IDirectMusicObject::ParseDescriptor>,<t DMUS_OBJECTDESC>, <i IDirectMusicLoader>
  479. */
  480. HRESULT CDMStyle::SetDescriptor(
  481. LPDMUS_OBJECTDESC pDesc) // @parm Descriptor with data about object.
  482. {
  483. return S_OK;
  484. }
  485. /*
  486. @method:(EXTERNAL) HRESULT | IDirectMusicObject | ParseDescriptor |
  487. Given a file stream, <om IDirectMusicObject::ParseDescriptor> scans the
  488. file for data which it can store in the <t DMUS_OBJECTDESC> structure.
  489. These include object name, GUID, version info, etc. All fields that
  490. are supplied are marked with the appropriate bit flags in
  491. <e DMUS_OBJECTDESC.dwValidData>.
  492. This is primarily used by the loader when scanning a directory for
  493. objects, and should not be of use to an application. However, if you
  494. implement an object type in DirectMusic, you should support this.
  495. @rdesc Returns one of the following
  496. @flag S_OK | Success
  497. @flag DMUS_E_INVALIDFILE | Not a valid file
  498. @xref <i IDirectMusicObject>, <om IDirectMusicObject::SetDescriptor>,
  499. <om IDirectMusicObject::GetDescriptor>,<t DMUS_OBJECTDESC>, <i IDirectMusicLoader>
  500. */
  501. HRESULT CDMStyle::ParseDescriptor(
  502. LPSTREAM pStream, // @parm Stream source for file.
  503. LPDMUS_OBJECTDESC pDesc) // @parm Descriptor to fill with data about file.
  504. {
  505. return S_OK;
  506. }
  507. #endif // ONLYAUTODOCS
  508. #endif //__CDMLOADER_H_