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.

1248 lines
32 KiB

  1. //
  2. // dmstydll.cpp
  3. //
  4. // Copyright (c) 1997-1999 Microsoft Corporation
  5. //
  6. // Note: Dll entry points as well as Class Factory implementations.
  7. //
  8. // READ THIS!!!!!!!!!!!!!!!!!!!!!!!!!!!
  9. //
  10. // 4530: C++ exception handler used, but unwind semantics are not enabled. Specify -GX
  11. //
  12. // We disable this because we use exceptions and do *not* specify -GX (USE_NATIVE_EH in
  13. // sources).
  14. //
  15. // The one place we use exceptions is around construction of objects that call
  16. // InitializeCriticalSection. We guarantee that it is safe to use in this case with
  17. // the restriction given by not using -GX (automatic objects in the call chain between
  18. // throw and handler are not destructed). Turning on -GX buys us nothing but +10% to code
  19. // size because of the unwind code.
  20. //
  21. // Any other use of exceptions must follow these restrictions or -GX must be turned on.
  22. //
  23. // READ THIS!!!!!!!!!!!!!!!!!!!!!!!!!!!
  24. //
  25. #pragma warning(disable:4530)
  26. #include <objbase.h>
  27. #include "debug.h"
  28. #include "debug.h"
  29. #include "..\shared\oledll.h"
  30. #include <initguid.h>
  31. #include "dmusici.h"
  32. #include "DMStyleP.h"
  33. #include "dmstyle.h"
  34. #include "dmsect.h"
  35. #include "chordtrk.h"
  36. #include "cmmdtrk.h"
  37. #include "styletrk.h"
  38. #include "motiftrk.h"
  39. #include "audtrk.h"
  40. #include "mutetrk.h"
  41. #include "mgentrk.h"
  42. #include "..\dmband\dmbndtrk.h"
  43. #include "..\shared\Validate.h"
  44. #include "..\shared\dmscriptautguids.h"
  45. //////////////////////////////////////////////////////////////////////
  46. // Globals
  47. // Version information
  48. //
  49. TCHAR g_szStyleFriendlyName[] = TEXT("DirectMusicStyle");
  50. TCHAR g_szStyleVerIndProgID[] = TEXT("Microsoft.DirectMusicStyle");
  51. TCHAR g_szStyleProgID[] = TEXT("Microsoft.DirectMusicStyle.1");
  52. TCHAR g_szSectionFriendlyName[] = TEXT("DirectMusicSection");
  53. TCHAR g_szSectionVerIndProgID[] = TEXT("Microsoft.DirectMusicSection");
  54. TCHAR g_szSectionProgID[] = TEXT("Microsoft.DirectMusicSection.1");
  55. TCHAR g_szChordTrackFriendlyName[] = TEXT("DirectMusicChordTrack");
  56. TCHAR g_szChordTrackVerIndProgID[] = TEXT("Microsoft.DirectMusicChordTrack");
  57. TCHAR g_szChordTrackProgID[] = TEXT("Microsoft.DirectMusicChordTrack.1");
  58. TCHAR g_szCommandTrackFriendlyName[] = TEXT("DirectMusicCommandTrack");
  59. TCHAR g_szCommandTrackVerIndProgID[] = TEXT("Microsoft.DirectMusicCommandTrack");
  60. TCHAR g_szCommandTrackProgID[] = TEXT("Microsoft.DirectMusicCommandTrack.1");
  61. TCHAR g_szStyleTrackFriendlyName[] = TEXT("DirectMusicStyleTrack");
  62. TCHAR g_szStyleTrackVerIndProgID[] = TEXT("Microsoft.DirectMusicStyleTrack");
  63. TCHAR g_szStyleTrackProgID[] = TEXT("Microsoft.DirectMusicStyleTrack.1");
  64. TCHAR g_szMotifTrackFriendlyName[] = TEXT("DirectMusicMotifTrack");
  65. TCHAR g_szMotifTrackVerIndProgID[] = TEXT("Microsoft.DirectMusicMotifTrack");
  66. TCHAR g_szMotifTrackProgID[] = TEXT("Microsoft.DirectMusicMotifTrack.1");
  67. TCHAR g_szMuteTrackFriendlyName[] = TEXT("DirectMusicMuteTrack");
  68. TCHAR g_szMuteTrackVerIndProgID[] = TEXT("Microsoft.DirectMusicMuteTrack");
  69. TCHAR g_szMuteTrackProgID[] = TEXT("Microsoft.DirectMusicMuteTrack.1");
  70. TCHAR g_szAuditionTrackFriendlyName[] = TEXT("DirectMusicAuditionTrack");
  71. TCHAR g_szAuditionTrackVerIndProgID[] = TEXT("Microsoft.DirectMusicAuditionTrack");
  72. TCHAR g_szAuditionTrackProgID[] = TEXT("Microsoft.DirectMusicAuditionTrack.1");
  73. TCHAR g_szMelGenTrackFriendlyName[] = TEXT("DirectMusicMelodyFormulationTrack");
  74. TCHAR g_szMelGenTrackVerIndProgID[] = TEXT("Microsoft.DirectMusicMelodyFormulationTrack");
  75. TCHAR g_szMelGenTrackProgID[] = TEXT("Microsoft.DirectMusicMelodyFormulationTrack.1");
  76. // Dll's hModule
  77. //
  78. HMODULE g_hModule = NULL;
  79. // Count of active components and class factory server locks
  80. //
  81. long g_cComponent = 0;
  82. long g_cLock = 0;
  83. //////////////////////////////////////////////////////////////////////
  84. // CDirectMusicStyleFactory::QueryInterface
  85. HRESULT __stdcall
  86. CDirectMusicStyleFactory::QueryInterface(const IID &iid,
  87. void **ppv)
  88. {
  89. V_INAME(CDirectMusicStyleFactory::QueryInterface);
  90. V_PTRPTR_WRITE(ppv);
  91. V_REFGUID(iid);
  92. if (iid == IID_IUnknown || iid == IID_IClassFactory) {
  93. *ppv = static_cast<IClassFactory*>(this);
  94. } else {
  95. *ppv = NULL;
  96. return E_NOINTERFACE;
  97. }
  98. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  99. return S_OK;
  100. }
  101. //////////////////////////////////////////////////////////////////////
  102. // CDirectMusicStyleFactory::AddRef
  103. ULONG __stdcall
  104. CDirectMusicStyleFactory::AddRef()
  105. {
  106. return InterlockedIncrement(&m_cRef);
  107. }
  108. //////////////////////////////////////////////////////////////////////
  109. // CDirectMusicStyleFactory::Release
  110. ULONG __stdcall
  111. CDirectMusicStyleFactory::Release()
  112. {
  113. if (!InterlockedDecrement(&m_cRef)) {
  114. delete this;
  115. return 0;
  116. }
  117. return m_cRef;
  118. }
  119. //////////////////////////////////////////////////////////////////////
  120. // CDirectMusicStyleFactory::CreateInstance
  121. HRESULT __stdcall
  122. CDirectMusicStyleFactory::CreateInstance(IUnknown* pUnknownOuter,
  123. const IID& iid,
  124. void** ppv)
  125. {
  126. HRESULT hr;
  127. if (pUnknownOuter) {
  128. return CLASS_E_NOAGGREGATION;
  129. }
  130. CDMStyle *pDM;
  131. try
  132. {
  133. pDM = new CDMStyle;
  134. }
  135. catch( ... )
  136. {
  137. return E_OUTOFMEMORY;
  138. }
  139. if (pDM == NULL) {
  140. return E_OUTOFMEMORY;
  141. }
  142. hr = pDM->QueryInterface(iid, ppv);
  143. pDM->Release();
  144. return hr;
  145. }
  146. //////////////////////////////////////////////////////////////////////
  147. // CDirectMusicStyleFactory::LockServer
  148. HRESULT __stdcall
  149. CDirectMusicStyleFactory::LockServer(BOOL bLock)
  150. {
  151. if (bLock) {
  152. InterlockedIncrement(&g_cLock);
  153. } else {
  154. InterlockedDecrement(&g_cLock);
  155. }
  156. return S_OK;
  157. }
  158. //////////////////////////////////////////////////////////////////////
  159. // CDirectMusicSectionFactory::QueryInterface
  160. HRESULT __stdcall
  161. CDirectMusicSectionFactory::QueryInterface(const IID &iid,
  162. void **ppv)
  163. {
  164. V_INAME(CDirectMusicSectionFactory::QueryInterface);
  165. V_PTRPTR_WRITE(ppv);
  166. V_REFGUID(iid);
  167. if (iid == IID_IUnknown || iid == IID_IClassFactory) {
  168. *ppv = static_cast<IClassFactory*>(this);
  169. } else {
  170. *ppv = NULL;
  171. return E_NOINTERFACE;
  172. }
  173. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  174. return S_OK;
  175. }
  176. //////////////////////////////////////////////////////////////////////
  177. // CDirectMusicSectionFactory::AddRef
  178. ULONG __stdcall
  179. CDirectMusicSectionFactory::AddRef()
  180. {
  181. return InterlockedIncrement(&m_cRef);
  182. }
  183. //////////////////////////////////////////////////////////////////////
  184. // CDirectMusicSectionFactory::Release
  185. ULONG __stdcall
  186. CDirectMusicSectionFactory::Release()
  187. {
  188. if (!InterlockedDecrement(&m_cRef)) {
  189. delete this;
  190. return 0;
  191. }
  192. return m_cRef;
  193. }
  194. //////////////////////////////////////////////////////////////////////
  195. // CDirectMusicSectionFactory::CreateInstance
  196. HRESULT __stdcall
  197. CDirectMusicSectionFactory::CreateInstance(IUnknown* pUnknownOuter,
  198. const IID& iid,
  199. void** ppv)
  200. {
  201. HRESULT hr;
  202. // DebugBreak();
  203. if (pUnknownOuter) {
  204. return CLASS_E_NOAGGREGATION;
  205. }
  206. CDMSection *pDM = new CDMSection;
  207. if (pDM == NULL) {
  208. return E_OUTOFMEMORY;
  209. }
  210. hr = pDM->QueryInterface(iid, ppv);
  211. pDM->Release();
  212. return hr;
  213. }
  214. //////////////////////////////////////////////////////////////////////
  215. // CDirectMusicSectionFactory::LockServer
  216. HRESULT __stdcall
  217. CDirectMusicSectionFactory::LockServer(BOOL bLock)
  218. {
  219. if (bLock) {
  220. InterlockedIncrement(&g_cLock);
  221. } else {
  222. InterlockedDecrement(&g_cLock);
  223. }
  224. return S_OK;
  225. }
  226. //////////////////////////////////////////////////////////////////////
  227. // CDirectMusicStyleTrackFactory::QueryInterface
  228. HRESULT __stdcall
  229. CDirectMusicStyleTrackFactory::QueryInterface(const IID &iid,
  230. void **ppv)
  231. {
  232. V_INAME(CDirectMusicStyleTrackFactory::QueryInterface);
  233. V_PTRPTR_WRITE(ppv);
  234. V_REFGUID(iid);
  235. if (iid == IID_IUnknown || iid == IID_IClassFactory) {
  236. *ppv = static_cast<IClassFactory*>(this);
  237. } else {
  238. *ppv = NULL;
  239. return E_NOINTERFACE;
  240. }
  241. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  242. return S_OK;
  243. }
  244. //////////////////////////////////////////////////////////////////////
  245. // CDirectMusicStyleTrackFactory::AddRef
  246. ULONG __stdcall
  247. CDirectMusicStyleTrackFactory::AddRef()
  248. {
  249. return InterlockedIncrement(&m_cRef);
  250. }
  251. //////////////////////////////////////////////////////////////////////
  252. // CDirectMusicStyleTrackFactory::Release
  253. ULONG __stdcall
  254. CDirectMusicStyleTrackFactory::Release()
  255. {
  256. if (!InterlockedDecrement(&m_cRef)) {
  257. delete this;
  258. return 0;
  259. }
  260. return m_cRef;
  261. }
  262. //////////////////////////////////////////////////////////////////////
  263. // CDirectMusicStyleTrackFactory::CreateInstance
  264. HRESULT __stdcall
  265. CDirectMusicStyleTrackFactory::CreateInstance(IUnknown* pUnknownOuter,
  266. const IID& iid,
  267. void** ppv)
  268. {
  269. HRESULT hr;
  270. // DebugBreak();
  271. if (pUnknownOuter) {
  272. return CLASS_E_NOAGGREGATION;
  273. }
  274. CStyleTrack *pDM;
  275. try
  276. {
  277. pDM = new CStyleTrack;
  278. }
  279. catch( ... )
  280. {
  281. return E_OUTOFMEMORY;
  282. }
  283. if (pDM == NULL) {
  284. return E_OUTOFMEMORY;
  285. }
  286. hr = pDM->QueryInterface(iid, ppv);
  287. pDM->Release();
  288. return hr;
  289. }
  290. //////////////////////////////////////////////////////////////////////
  291. // CDirectMusicStyleTrackFactory::LockServer
  292. HRESULT __stdcall
  293. CDirectMusicStyleTrackFactory::LockServer(BOOL bLock)
  294. {
  295. if (bLock) {
  296. InterlockedIncrement(&g_cLock);
  297. } else {
  298. InterlockedDecrement(&g_cLock);
  299. }
  300. return S_OK;
  301. }
  302. //////////////////////////////////////////////////////////////////////
  303. // CDirectMusicCommandTrackFactory::QueryInterface
  304. HRESULT __stdcall
  305. CDirectMusicCommandTrackFactory::QueryInterface(const IID &iid,
  306. void **ppv)
  307. {
  308. V_INAME(CDirectMusicCommandTrackFactory::QueryInterface);
  309. V_PTRPTR_WRITE(ppv);
  310. V_REFGUID(iid);
  311. if (iid == IID_IUnknown || iid == IID_IClassFactory) {
  312. *ppv = static_cast<IClassFactory*>(this);
  313. } else {
  314. *ppv = NULL;
  315. return E_NOINTERFACE;
  316. }
  317. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  318. return S_OK;
  319. }
  320. //////////////////////////////////////////////////////////////////////
  321. // CDirectMusicCommandTrackFactory::AddRef
  322. ULONG __stdcall
  323. CDirectMusicCommandTrackFactory::AddRef()
  324. {
  325. return InterlockedIncrement(&m_cRef);
  326. }
  327. //////////////////////////////////////////////////////////////////////
  328. // CDirectMusicCommandTrackFactory::Release
  329. ULONG __stdcall
  330. CDirectMusicCommandTrackFactory::Release()
  331. {
  332. if (!InterlockedDecrement(&m_cRef)) {
  333. delete this;
  334. return 0;
  335. }
  336. return m_cRef;
  337. }
  338. //////////////////////////////////////////////////////////////////////
  339. // CDirectMusicCommandTrackFactory::CreateInstance
  340. HRESULT __stdcall
  341. CDirectMusicCommandTrackFactory::CreateInstance(IUnknown* pUnknownOuter,
  342. const IID& iid,
  343. void** ppv)
  344. {
  345. HRESULT hr;
  346. // DebugBreak();
  347. if (pUnknownOuter) {
  348. return CLASS_E_NOAGGREGATION;
  349. }
  350. CCommandTrack *pDM;
  351. try
  352. {
  353. pDM = new CCommandTrack;
  354. }
  355. catch( ... )
  356. {
  357. return E_OUTOFMEMORY;
  358. }
  359. if (pDM == NULL) {
  360. return E_OUTOFMEMORY;
  361. }
  362. hr = pDM->QueryInterface(iid, ppv);
  363. pDM->Release();
  364. return hr;
  365. }
  366. //////////////////////////////////////////////////////////////////////
  367. // CDirectMusicCommandTrackFactory::LockServer
  368. HRESULT __stdcall
  369. CDirectMusicCommandTrackFactory::LockServer(BOOL bLock)
  370. {
  371. if (bLock) {
  372. InterlockedIncrement(&g_cLock);
  373. } else {
  374. InterlockedDecrement(&g_cLock);
  375. }
  376. return S_OK;
  377. }
  378. //////////////////////////////////////////////////////////////////////
  379. // CDirectMusicChordTrackFactory::QueryInterface
  380. HRESULT __stdcall
  381. CDirectMusicChordTrackFactory::QueryInterface(const IID &iid,
  382. void **ppv)
  383. {
  384. V_INAME(CDirectMusicChordTrackFactory::QueryInterface);
  385. V_PTRPTR_WRITE(ppv);
  386. V_REFGUID(iid);
  387. if (iid == IID_IUnknown || iid == IID_IClassFactory) {
  388. *ppv = static_cast<IClassFactory*>(this);
  389. } else {
  390. *ppv = NULL;
  391. return E_NOINTERFACE;
  392. }
  393. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  394. return S_OK;
  395. }
  396. //////////////////////////////////////////////////////////////////////
  397. // CDirectMusicChordTrackFactory::AddRef
  398. ULONG __stdcall
  399. CDirectMusicChordTrackFactory::AddRef()
  400. {
  401. return InterlockedIncrement(&m_cRef);
  402. }
  403. //////////////////////////////////////////////////////////////////////
  404. // CDirectMusicChordTrackFactory::Release
  405. ULONG __stdcall
  406. CDirectMusicChordTrackFactory::Release()
  407. {
  408. if (!InterlockedDecrement(&m_cRef)) {
  409. delete this;
  410. return 0;
  411. }
  412. return m_cRef;
  413. }
  414. //////////////////////////////////////////////////////////////////////
  415. // CDirectMusicChordTrackFactory::CreateInstance
  416. HRESULT __stdcall
  417. CDirectMusicChordTrackFactory::CreateInstance(IUnknown* pUnknownOuter,
  418. const IID& iid,
  419. void** ppv)
  420. {
  421. HRESULT hr;
  422. // DebugBreak();
  423. if (pUnknownOuter) {
  424. return CLASS_E_NOAGGREGATION;
  425. }
  426. CChordTrack *pDM;
  427. try
  428. {
  429. pDM = new CChordTrack;
  430. }
  431. catch( ... )
  432. {
  433. return E_OUTOFMEMORY;
  434. }
  435. if (pDM == NULL) {
  436. return E_OUTOFMEMORY;
  437. }
  438. hr = pDM->QueryInterface(iid, ppv);
  439. pDM->Release();
  440. return hr;
  441. }
  442. //////////////////////////////////////////////////////////////////////
  443. // CDirectMusicChordTrackFactory::LockServer
  444. HRESULT __stdcall
  445. CDirectMusicChordTrackFactory::LockServer(BOOL bLock)
  446. {
  447. if (bLock) {
  448. InterlockedIncrement(&g_cLock);
  449. } else {
  450. InterlockedDecrement(&g_cLock);
  451. }
  452. return S_OK;
  453. }
  454. ///////////////////////////////////////////////////////////////////////
  455. // CDirectMusicMotifTrackFactory::QueryInterface
  456. HRESULT __stdcall
  457. CDirectMusicMotifTrackFactory::QueryInterface(const IID &iid,
  458. void **ppv)
  459. {
  460. V_INAME(CDirectMusicMotifTrackFactory::QueryInterface);
  461. V_PTRPTR_WRITE(ppv);
  462. V_REFGUID(iid);
  463. if (iid == IID_IUnknown || iid == IID_IClassFactory) {
  464. *ppv = static_cast<IClassFactory*>(this);
  465. } else {
  466. *ppv = NULL;
  467. return E_NOINTERFACE;
  468. }
  469. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  470. return S_OK;
  471. }
  472. //////////////////////////////////////////////////////////////////////
  473. // CDirectMusicMotifTrackFactory::AddRef
  474. ULONG __stdcall
  475. CDirectMusicMotifTrackFactory::AddRef()
  476. {
  477. return InterlockedIncrement(&m_cRef);
  478. }
  479. //////////////////////////////////////////////////////////////////////
  480. // CDirectMusicMotifTrackFactory::Release
  481. ULONG __stdcall
  482. CDirectMusicMotifTrackFactory::Release()
  483. {
  484. if (!InterlockedDecrement(&m_cRef)) {
  485. delete this;
  486. return 0;
  487. }
  488. return m_cRef;
  489. }
  490. //////////////////////////////////////////////////////////////////////
  491. // CDirectMusicMotifTrackFactory::CreateInstance
  492. HRESULT __stdcall
  493. CDirectMusicMotifTrackFactory::CreateInstance(IUnknown* pUnknownOuter,
  494. const IID& iid,
  495. void** ppv)
  496. {
  497. HRESULT hr;
  498. // DebugBreak();
  499. if (pUnknownOuter) {
  500. return CLASS_E_NOAGGREGATION;
  501. }
  502. CMotifTrack *pDM;
  503. try
  504. {
  505. pDM = new CMotifTrack;
  506. }
  507. catch( ... )
  508. {
  509. return E_OUTOFMEMORY;
  510. }
  511. if (pDM == NULL) {
  512. return E_OUTOFMEMORY;
  513. }
  514. hr = pDM->QueryInterface(iid, ppv);
  515. pDM->Release();
  516. return hr;
  517. }
  518. //////////////////////////////////////////////////////////////////////
  519. // CDirectMusicMotifTrackFactory::LockServer
  520. HRESULT __stdcall
  521. CDirectMusicMotifTrackFactory::LockServer(BOOL bLock)
  522. {
  523. if (bLock) {
  524. InterlockedIncrement(&g_cLock);
  525. } else {
  526. InterlockedDecrement(&g_cLock);
  527. }
  528. return S_OK;
  529. }
  530. //////////////////////////////////////////////////////////////////////
  531. // CDirectMusicMuteTrackFactory::QueryInterface
  532. HRESULT __stdcall
  533. CDirectMusicMuteTrackFactory::QueryInterface(const IID &iid,
  534. void **ppv)
  535. {
  536. V_INAME(CDirectMusicMuteTrackFactory::QueryInterface);
  537. V_PTRPTR_WRITE(ppv);
  538. V_REFGUID(iid);
  539. if (iid == IID_IUnknown || iid == IID_IClassFactory) {
  540. *ppv = static_cast<IClassFactory*>(this);
  541. } else {
  542. *ppv = NULL;
  543. return E_NOINTERFACE;
  544. }
  545. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  546. return S_OK;
  547. }
  548. //////////////////////////////////////////////////////////////////////
  549. // CDirectMusicMuteTrackFactory::AddRef
  550. ULONG __stdcall
  551. CDirectMusicMuteTrackFactory::AddRef()
  552. {
  553. return InterlockedIncrement(&m_cRef);
  554. }
  555. //////////////////////////////////////////////////////////////////////
  556. // CDirectMusicMuteTrackFactory::Release
  557. ULONG __stdcall
  558. CDirectMusicMuteTrackFactory::Release()
  559. {
  560. if (!InterlockedDecrement(&m_cRef)) {
  561. delete this;
  562. return 0;
  563. }
  564. return m_cRef;
  565. }
  566. //////////////////////////////////////////////////////////////////////
  567. // CDirectMusicMuteTrackFactory::CreateInstance
  568. HRESULT __stdcall
  569. CDirectMusicMuteTrackFactory::CreateInstance(IUnknown* pUnknownOuter,
  570. const IID& iid,
  571. void** ppv)
  572. {
  573. HRESULT hr;
  574. // DebugBreak();
  575. if (pUnknownOuter) {
  576. return CLASS_E_NOAGGREGATION;
  577. }
  578. CMuteTrack *pDM;
  579. try
  580. {
  581. pDM = new CMuteTrack;
  582. }
  583. catch( ... )
  584. {
  585. pDM = NULL;
  586. }
  587. if (pDM == NULL) {
  588. return E_OUTOFMEMORY;
  589. }
  590. hr = pDM->QueryInterface(iid, ppv);
  591. pDM->Release();
  592. return hr;
  593. }
  594. //////////////////////////////////////////////////////////////////////
  595. // CDirectMusicMuteTrackFactory::LockServer
  596. HRESULT __stdcall
  597. CDirectMusicMuteTrackFactory::LockServer(BOOL bLock)
  598. {
  599. if (bLock) {
  600. InterlockedIncrement(&g_cLock);
  601. } else {
  602. InterlockedDecrement(&g_cLock);
  603. }
  604. return S_OK;
  605. }
  606. /////////////////////////////////////////////////////////////////////
  607. // CDirectMusicAuditionTrackFactory::QueryInterface
  608. HRESULT __stdcall
  609. CDirectMusicAuditionTrackFactory::QueryInterface(const IID &iid,
  610. void **ppv)
  611. {
  612. V_INAME(CDirectMusicAuditionTrackFactory::QueryInterface);
  613. V_PTRPTR_WRITE(ppv);
  614. V_REFGUID(iid);
  615. if (iid == IID_IUnknown || iid == IID_IClassFactory) {
  616. *ppv = static_cast<IClassFactory*>(this);
  617. } else {
  618. *ppv = NULL;
  619. return E_NOINTERFACE;
  620. }
  621. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  622. return S_OK;
  623. }
  624. //////////////////////////////////////////////////////////////////////
  625. // CDirectMusicAuditionTrackFactory::AddRef
  626. ULONG __stdcall
  627. CDirectMusicAuditionTrackFactory::AddRef()
  628. {
  629. return InterlockedIncrement(&m_cRef);
  630. }
  631. //////////////////////////////////////////////////////////////////////
  632. // CDirectMusicAuditionTrackFactory::Release
  633. ULONG __stdcall
  634. CDirectMusicAuditionTrackFactory::Release()
  635. {
  636. if (!InterlockedDecrement(&m_cRef)) {
  637. delete this;
  638. return 0;
  639. }
  640. return m_cRef;
  641. }
  642. //////////////////////////////////////////////////////////////////////
  643. // CDirectMusicAuditionTrackFactory::CreateInstance
  644. HRESULT __stdcall
  645. CDirectMusicAuditionTrackFactory::CreateInstance(IUnknown* pUnknownOuter,
  646. const IID& iid,
  647. void** ppv)
  648. {
  649. HRESULT hr;
  650. if (pUnknownOuter) {
  651. return CLASS_E_NOAGGREGATION;
  652. }
  653. CAuditionTrack *pDM;
  654. try
  655. {
  656. pDM = new CAuditionTrack;
  657. }
  658. catch( ... )
  659. {
  660. return E_OUTOFMEMORY;
  661. }
  662. if (pDM == NULL) {
  663. return E_OUTOFMEMORY;
  664. }
  665. hr = pDM->QueryInterface(iid, ppv);
  666. pDM->Release();
  667. return hr;
  668. }
  669. //////////////////////////////////////////////////////////////////////
  670. // CDirectMusicAuditionTrackFactory::LockServer
  671. HRESULT __stdcall
  672. CDirectMusicAuditionTrackFactory::LockServer(BOOL bLock)
  673. {
  674. if (bLock) {
  675. InterlockedIncrement(&g_cLock);
  676. } else {
  677. InterlockedDecrement(&g_cLock);
  678. }
  679. return S_OK;
  680. }
  681. //////////////////////////////////////////////////////////////////////
  682. // CDirectMusicMelodyFormulationTrackFactory::QueryInterface
  683. HRESULT __stdcall
  684. CDirectMusicMelodyFormulationTrackFactory::QueryInterface(const IID &iid,
  685. void **ppv)
  686. {
  687. V_INAME(CDirectMusicMelodyFormulationTrackFactory::QueryInterface);
  688. V_PTRPTR_WRITE(ppv);
  689. V_REFGUID(iid);
  690. if (iid == IID_IUnknown || iid == IID_IClassFactory) {
  691. *ppv = static_cast<IClassFactory*>(this);
  692. } else {
  693. *ppv = NULL;
  694. return E_NOINTERFACE;
  695. }
  696. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  697. return S_OK;
  698. }
  699. //////////////////////////////////////////////////////////////////////
  700. // CDirectMusicMelodyFormulationTrackFactory::AddRef
  701. ULONG __stdcall
  702. CDirectMusicMelodyFormulationTrackFactory::AddRef()
  703. {
  704. return InterlockedIncrement(&m_cRef);
  705. }
  706. //////////////////////////////////////////////////////////////////////
  707. // CDirectMusicMelodyFormulationTrackFactory::Release
  708. ULONG __stdcall
  709. CDirectMusicMelodyFormulationTrackFactory::Release()
  710. {
  711. if (!InterlockedDecrement(&m_cRef)) {
  712. delete this;
  713. return 0;
  714. }
  715. return m_cRef;
  716. }
  717. //////////////////////////////////////////////////////////////////////
  718. // CDirectMusicMelodyFormulationTrackFactory::CreateInstance
  719. HRESULT __stdcall
  720. CDirectMusicMelodyFormulationTrackFactory::CreateInstance(IUnknown* pUnknownOuter,
  721. const IID& iid,
  722. void** ppv)
  723. {
  724. HRESULT hr;
  725. if (pUnknownOuter) {
  726. return CLASS_E_NOAGGREGATION;
  727. }
  728. CMelodyFormulationTrack *pDM;
  729. try
  730. {
  731. pDM = new CMelodyFormulationTrack;
  732. }
  733. catch( ... )
  734. {
  735. return E_OUTOFMEMORY;
  736. }
  737. if (pDM == NULL) {
  738. return E_OUTOFMEMORY;
  739. }
  740. hr = pDM->QueryInterface(iid, ppv);
  741. pDM->Release();
  742. return hr;
  743. }
  744. //////////////////////////////////////////////////////////////////////
  745. // CDirectMusicMelodyFormulationTrackFactory::LockServer
  746. HRESULT __stdcall
  747. CDirectMusicMelodyFormulationTrackFactory::LockServer(BOOL bLock)
  748. {
  749. if (bLock) {
  750. InterlockedIncrement(&g_cLock);
  751. } else {
  752. InterlockedDecrement(&g_cLock);
  753. }
  754. return S_OK;
  755. }
  756. //////////////////////////////////////////////////////////////////////
  757. // Standard calls needed to be an inproc server
  758. //////////////////////////////////////////////////////////////////////
  759. // DllCanUnloadNow
  760. STDAPI DllCanUnloadNow()
  761. {
  762. if (g_cComponent || g_cLock) {
  763. return S_FALSE;
  764. }
  765. return S_OK;
  766. }
  767. //////////////////////////////////////////////////////////////////////
  768. // DllGetClassObject
  769. STDAPI DllGetClassObject(const CLSID& clsid,
  770. const IID& iid,
  771. void** ppv)
  772. {
  773. IUnknown* pIUnknown = NULL;
  774. if(clsid == CLSID_DirectMusicStyle)
  775. {
  776. pIUnknown = static_cast<IUnknown*> (new CDirectMusicStyleFactory);
  777. if(!pIUnknown)
  778. {
  779. return E_OUTOFMEMORY;
  780. }
  781. }
  782. else if(clsid == CLSID_DMSection)
  783. {
  784. pIUnknown = static_cast<IUnknown*> (new CDirectMusicSectionFactory);
  785. if(!pIUnknown)
  786. {
  787. return E_OUTOFMEMORY;
  788. }
  789. }
  790. else if(clsid == CLSID_DirectMusicChordTrack)
  791. {
  792. pIUnknown = static_cast<IUnknown*> (new CDirectMusicChordTrackFactory);
  793. if(!pIUnknown)
  794. {
  795. return E_OUTOFMEMORY;
  796. }
  797. }
  798. else if(clsid == CLSID_DirectMusicCommandTrack)
  799. {
  800. pIUnknown = static_cast<IUnknown*> (new CDirectMusicCommandTrackFactory);
  801. if(!pIUnknown)
  802. {
  803. return E_OUTOFMEMORY;
  804. }
  805. }
  806. else if(clsid == CLSID_DirectMusicStyleTrack)
  807. {
  808. pIUnknown = static_cast<IUnknown*> (new CDirectMusicStyleTrackFactory);
  809. if(!pIUnknown)
  810. {
  811. return E_OUTOFMEMORY;
  812. }
  813. }
  814. else if(clsid == CLSID_DirectMusicMotifTrack)
  815. {
  816. pIUnknown = static_cast<IUnknown*> (new CDirectMusicMotifTrackFactory);
  817. if(!pIUnknown)
  818. {
  819. return E_OUTOFMEMORY;
  820. }
  821. }
  822. else if(clsid == CLSID_DirectMusicMuteTrack)
  823. {
  824. pIUnknown = static_cast<IUnknown*> (new CDirectMusicMuteTrackFactory);
  825. if(!pIUnknown)
  826. {
  827. return E_OUTOFMEMORY;
  828. }
  829. }
  830. else if(clsid == CLSID_DirectMusicAuditionTrack)
  831. {
  832. pIUnknown = static_cast<IUnknown*> (new CDirectMusicAuditionTrackFactory);
  833. if(!pIUnknown)
  834. {
  835. return E_OUTOFMEMORY;
  836. }
  837. }
  838. else if(clsid == CLSID_DirectMusicMelodyFormulationTrack)
  839. {
  840. pIUnknown = static_cast<IUnknown*> (new CDirectMusicMelodyFormulationTrackFactory);
  841. if(!pIUnknown)
  842. {
  843. return E_OUTOFMEMORY;
  844. }
  845. }
  846. else
  847. {
  848. return CLASS_E_CLASSNOTAVAILABLE;
  849. }
  850. HRESULT hr = pIUnknown->QueryInterface(iid, ppv);
  851. pIUnknown->Release();
  852. return hr;
  853. }
  854. //////////////////////////////////////////////////////////////////////
  855. // DllUnregisterServer
  856. STDAPI DllUnregisterServer()
  857. {
  858. UnregisterServer(CLSID_DirectMusicStyle,
  859. g_szStyleFriendlyName,
  860. g_szStyleVerIndProgID,
  861. g_szStyleProgID);
  862. UnregisterServer(CLSID_DMSection,
  863. g_szSectionFriendlyName,
  864. g_szSectionVerIndProgID,
  865. g_szSectionProgID);
  866. UnregisterServer(CLSID_DirectMusicChordTrack,
  867. g_szChordTrackFriendlyName,
  868. g_szChordTrackVerIndProgID,
  869. g_szChordTrackProgID);
  870. UnregisterServer(CLSID_DirectMusicCommandTrack,
  871. g_szCommandTrackFriendlyName,
  872. g_szCommandTrackVerIndProgID,
  873. g_szCommandTrackProgID);
  874. UnregisterServer(CLSID_DirectMusicStyleTrack,
  875. g_szStyleTrackFriendlyName,
  876. g_szStyleTrackVerIndProgID,
  877. g_szStyleTrackProgID);
  878. UnregisterServer(CLSID_DirectMusicMotifTrack,
  879. g_szMotifTrackFriendlyName,
  880. g_szMotifTrackVerIndProgID,
  881. g_szMotifTrackProgID);
  882. UnregisterServer(CLSID_DirectMusicMuteTrack,
  883. g_szMuteTrackFriendlyName,
  884. g_szMuteTrackVerIndProgID,
  885. g_szMuteTrackProgID);
  886. UnregisterServer(CLSID_DirectMusicAuditionTrack,
  887. g_szAuditionTrackFriendlyName,
  888. g_szAuditionTrackVerIndProgID,
  889. g_szAuditionTrackProgID);
  890. UnregisterServer(CLSID_DirectMusicMelodyFormulationTrack,
  891. g_szMelGenTrackFriendlyName,
  892. g_szMelGenTrackVerIndProgID,
  893. g_szMelGenTrackProgID);
  894. return S_OK;
  895. }
  896. //////////////////////////////////////////////////////////////////////
  897. // DllRegisterServer
  898. STDAPI DllRegisterServer()
  899. {
  900. RegisterServer(g_hModule,
  901. CLSID_DirectMusicStyle,
  902. g_szStyleFriendlyName,
  903. g_szStyleVerIndProgID,
  904. g_szStyleProgID);
  905. RegisterServer(g_hModule,
  906. CLSID_DMSection,
  907. g_szSectionFriendlyName,
  908. g_szSectionVerIndProgID,
  909. g_szSectionProgID);
  910. RegisterServer(g_hModule,
  911. CLSID_DirectMusicChordTrack,
  912. g_szChordTrackFriendlyName,
  913. g_szChordTrackVerIndProgID,
  914. g_szChordTrackProgID);
  915. RegisterServer(g_hModule,
  916. CLSID_DirectMusicCommandTrack,
  917. g_szCommandTrackFriendlyName,
  918. g_szCommandTrackVerIndProgID,
  919. g_szCommandTrackProgID);
  920. RegisterServer(g_hModule,
  921. CLSID_DirectMusicStyleTrack,
  922. g_szStyleTrackFriendlyName,
  923. g_szStyleTrackVerIndProgID,
  924. g_szStyleTrackProgID);
  925. RegisterServer(g_hModule,
  926. CLSID_DirectMusicMotifTrack,
  927. g_szMotifTrackFriendlyName,
  928. g_szMotifTrackVerIndProgID,
  929. g_szMotifTrackProgID);
  930. RegisterServer(g_hModule,
  931. CLSID_DirectMusicMuteTrack,
  932. g_szMuteTrackFriendlyName,
  933. g_szMuteTrackVerIndProgID,
  934. g_szMuteTrackProgID);
  935. RegisterServer(g_hModule,
  936. CLSID_DirectMusicAuditionTrack,
  937. g_szAuditionTrackFriendlyName,
  938. g_szAuditionTrackVerIndProgID,
  939. g_szAuditionTrackProgID);
  940. RegisterServer(g_hModule,
  941. CLSID_DirectMusicMelodyFormulationTrack,
  942. g_szMelGenTrackFriendlyName,
  943. g_szMelGenTrackVerIndProgID,
  944. g_szMelGenTrackProgID);
  945. return S_OK;
  946. }
  947. //////////////////////////////////////////////////////////////////////
  948. // Standard Win32 DllMain
  949. //////////////////////////////////////////////////////////////////////
  950. // DllMain
  951. #ifdef DBG
  952. static char* aszReasons[] =
  953. {
  954. "DLL_PROCESS_DETACH",
  955. "DLL_PROCESS_ATTACH",
  956. "DLL_THREAD_ATTACH",
  957. "DLL_THREAD_DETACH"
  958. };
  959. const DWORD nReasons = (sizeof(aszReasons) / sizeof(char*));
  960. #endif
  961. BOOL APIENTRY DllMain(HINSTANCE hModule,
  962. DWORD dwReason,
  963. void *lpReserved)
  964. {
  965. static int nReferenceCount = 0;
  966. #ifdef DBG
  967. if (dwReason < nReasons)
  968. {
  969. TraceI(0, "DllMain: %s\n", (LPSTR)aszReasons[dwReason]);
  970. }
  971. else
  972. {
  973. TraceI(0, "DllMain: Unknown dwReason <%u>\n", dwReason);
  974. }
  975. #endif
  976. switch(dwReason)
  977. {
  978. case DLL_PROCESS_ATTACH:
  979. if (++nReferenceCount == 1)
  980. {
  981. #ifdef DBG
  982. DebugInit();
  983. #endif
  984. if (!DisableThreadLibraryCalls(hModule))
  985. {
  986. TraceI(0, "DisableThreadLibraryCalls failed.\n");
  987. }
  988. g_hModule = hModule;
  989. }
  990. break;
  991. #ifdef DBG
  992. case DLL_PROCESS_DETACH:
  993. if (--nReferenceCount == 0)
  994. {
  995. TraceI(-1, "Unloading g_cLock %d g_cComponent %d\n", g_cLock, g_cComponent);
  996. // Assert if we still have some objects hanging around
  997. assert(g_cComponent == 0);
  998. assert(g_cLock == 0);
  999. }
  1000. break;
  1001. #endif
  1002. }
  1003. return TRUE;
  1004. }