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.

858 lines
25 KiB

  1. //
  2. // dmprfdll.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 <initguid.h>
  28. #include <mmsystem.h>
  29. #include <dsoundp.h>
  30. #include "debug.h"
  31. #define ASSERT assert
  32. #include "debug.h"
  33. #include "dmprfdll.h"
  34. #include "dmperf.h"
  35. #include "dmsegobj.h"
  36. #include "song.h"
  37. #include "seqtrack.h"
  38. #include "sysextrk.h"
  39. #include "tempotrk.h"
  40. #include "tsigtrk.h"
  41. #include "marktrk.h"
  42. #include "wavtrack.h"
  43. #include "segtrtrk.h"
  44. #include "lyrictrk.h"
  45. #include "ParamTrk.h"
  46. #include "dmgraph.h"
  47. #include "dmusicc.h"
  48. #include "dmusici.h"
  49. #include "dmusicf.h"
  50. #include "..\shared\oledll.h"
  51. #include "..\dmstyle\dmstylep.h"
  52. #include "..\dmband\dmbndtrk.h"
  53. #include "..\shared\dmstrm.h"
  54. #include "..\shared\Validate.h"
  55. #include "dmksctrl.h"
  56. #include "dmscriptautguids.h"
  57. #include "audpath.h"
  58. #include "..\dswave\dswave.h"
  59. #include "dsoundp.h" // For IDirectSoundPrivate
  60. bool g_fInitCS = false;
  61. CRITICAL_SECTION g_CritSec;
  62. //////////////////////////////////////////////////////////////////////
  63. // Globals
  64. // Dll's hModule
  65. //
  66. HMODULE g_hModule = NULL;
  67. // Count of active components and class factory server locks
  68. //
  69. long g_cComponent = 0;
  70. long g_cLock = 0;
  71. // Flags DMI_F_xxx from dmusicp.h
  72. //
  73. DWORD g_fFlags;
  74. static char const g_szDoEmulation[] = "DoEmulation";
  75. // CClassFactory::QueryInterface
  76. //
  77. HRESULT __stdcall
  78. CClassFactory::QueryInterface(const IID &iid,
  79. void **ppv)
  80. {
  81. if (iid == IID_IUnknown || iid == IID_IClassFactory) {
  82. *ppv = static_cast<IClassFactory*>(this);
  83. } else {
  84. *ppv = NULL;
  85. return E_NOINTERFACE;
  86. }
  87. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  88. return S_OK;
  89. }
  90. CClassFactory::CClassFactory(DWORD dwClassType)
  91. {
  92. m_cRef = 1;
  93. m_dwClassType = dwClassType;
  94. InterlockedIncrement(&g_cLock);
  95. }
  96. CClassFactory::~CClassFactory()
  97. {
  98. InterlockedDecrement(&g_cLock);
  99. }
  100. // CClassFactory::AddRef
  101. //
  102. ULONG __stdcall
  103. CClassFactory::AddRef()
  104. {
  105. return InterlockedIncrement(&m_cRef);
  106. }
  107. // CClassFactory::Release
  108. //
  109. ULONG __stdcall
  110. CClassFactory::Release()
  111. {
  112. if (!InterlockedDecrement(&m_cRef)) {
  113. delete this;
  114. return 0;
  115. }
  116. return m_cRef;
  117. }
  118. // CClassFactory::CreateInstance
  119. //
  120. //
  121. HRESULT __stdcall
  122. CClassFactory::CreateInstance(IUnknown* pUnknownOuter,
  123. const IID& iid,
  124. void** ppv)
  125. {
  126. HRESULT hr;
  127. if (pUnknownOuter) {
  128. return CLASS_E_NOAGGREGATION;
  129. }
  130. switch (m_dwClassType)
  131. {
  132. case CLASS_PERFORMANCE:
  133. {
  134. CPerformance *pInst;
  135. try
  136. {
  137. pInst = new CPerformance;
  138. }
  139. catch( ... )
  140. {
  141. hr = E_OUTOFMEMORY;
  142. break;
  143. }
  144. if (pInst == NULL) {
  145. hr = E_OUTOFMEMORY;
  146. break;
  147. }
  148. hr = pInst->QueryInterface(iid, ppv);
  149. pInst->Release();
  150. }
  151. break;
  152. case CLASS_GRAPH:
  153. {
  154. CGraph *pInst = new CGraph;
  155. if (pInst == NULL) {
  156. hr = E_OUTOFMEMORY;
  157. break;
  158. }
  159. hr = pInst->QueryInterface(iid, ppv);
  160. pInst->Release();
  161. }
  162. break;
  163. case CLASS_SEGMENT:
  164. {
  165. CSegment *pInst = new CSegment;
  166. if (pInst == NULL) {
  167. hr = E_OUTOFMEMORY;
  168. break;
  169. }
  170. // The segment is initialized with a ref count of 0, so QI will set it to 1.
  171. hr = pInst->QueryInterface(iid, ppv);
  172. }
  173. break;
  174. case CLASS_SONG:
  175. {
  176. CSong *pInst = new CSong;
  177. if (pInst == NULL) {
  178. hr = E_OUTOFMEMORY;
  179. break;
  180. }
  181. hr = pInst->QueryInterface(iid, ppv);
  182. pInst->Release();
  183. }
  184. break;
  185. case CLASS_AUDIOPATH:
  186. {
  187. CAudioPathConfig *pInst;
  188. try
  189. {
  190. pInst = new CAudioPathConfig;
  191. }
  192. catch( ... )
  193. {
  194. hr = E_OUTOFMEMORY;
  195. break;
  196. }
  197. if (pInst == NULL) {
  198. hr = E_OUTOFMEMORY;
  199. break;
  200. }
  201. hr = pInst->QueryInterface(iid, ppv);
  202. pInst->Release();
  203. }
  204. break;
  205. case CLASS_SEQTRACK:
  206. {
  207. CSeqTrack *pInst;
  208. try
  209. {
  210. pInst = new CSeqTrack;
  211. }
  212. catch( ... )
  213. {
  214. hr = E_OUTOFMEMORY;
  215. break;
  216. }
  217. if (pInst == NULL) {
  218. hr = E_OUTOFMEMORY;
  219. break;
  220. }
  221. hr = pInst->QueryInterface(iid, ppv);
  222. pInst->Release();
  223. }
  224. break;
  225. case CLASS_SYSEXTRACK:
  226. {
  227. CSysExTrack *pInst;
  228. try
  229. {
  230. pInst = new CSysExTrack;
  231. }
  232. catch( ... )
  233. {
  234. hr = E_OUTOFMEMORY;
  235. break;
  236. }
  237. if (pInst == NULL) {
  238. hr = E_OUTOFMEMORY;
  239. break;
  240. }
  241. hr = pInst->QueryInterface(iid, ppv);
  242. pInst->Release();
  243. }
  244. break;
  245. case CLASS_TEMPOTRACK:
  246. {
  247. CTempoTrack *pInst;
  248. try
  249. {
  250. pInst = new CTempoTrack;
  251. }
  252. catch( ... )
  253. {
  254. hr = E_OUTOFMEMORY;
  255. break;
  256. }
  257. if (pInst == NULL) {
  258. hr = E_OUTOFMEMORY;
  259. break;
  260. }
  261. hr = pInst->QueryInterface(iid, ppv);
  262. pInst->Release();
  263. }
  264. break;
  265. case CLASS_TIMESIGTRACK:
  266. {
  267. CTimeSigTrack *pInst;
  268. try
  269. {
  270. pInst = new CTimeSigTrack;
  271. }
  272. catch( ... )
  273. {
  274. hr = E_OUTOFMEMORY;
  275. break;
  276. }
  277. if (pInst == NULL) {
  278. hr = E_OUTOFMEMORY;
  279. break;
  280. }
  281. hr = pInst->QueryInterface(iid, ppv);
  282. pInst->Release();
  283. }
  284. break;
  285. case CLASS_MARKERTRACK:
  286. {
  287. CMarkerTrack *pInst;
  288. try
  289. {
  290. pInst = new CMarkerTrack;
  291. }
  292. catch( ... )
  293. {
  294. hr = E_OUTOFMEMORY;
  295. break;
  296. }
  297. if (pInst == NULL) {
  298. hr = E_OUTOFMEMORY;
  299. break;
  300. }
  301. hr = pInst->QueryInterface(iid, ppv);
  302. pInst->Release();
  303. }
  304. break;
  305. case CLASS_WAVETRACK:
  306. {
  307. CWavTrack *pInst;
  308. try
  309. {
  310. pInst = new CWavTrack;
  311. }
  312. catch( ... )
  313. {
  314. hr = E_OUTOFMEMORY;
  315. break;
  316. }
  317. if (pInst == NULL) {
  318. hr = E_OUTOFMEMORY;
  319. break;
  320. }
  321. hr = pInst->QueryInterface(iid, ppv);
  322. pInst->Release();
  323. }
  324. break;
  325. case CLASS_TRIGGERTRACK:
  326. {
  327. try
  328. {
  329. hr = TrackHelpCreateInstance<CSegTriggerTrack>(pUnknownOuter, iid, ppv);
  330. }
  331. catch( ... )
  332. {
  333. hr = E_OUTOFMEMORY;
  334. }
  335. }
  336. break;
  337. case CLASS_LYRICSTRACK:
  338. {
  339. try
  340. {
  341. hr = TrackHelpCreateInstance<CLyricsTrack>(pUnknownOuter, iid, ppv);
  342. }
  343. catch( ... )
  344. {
  345. hr = E_OUTOFMEMORY;
  346. }
  347. }
  348. break;
  349. case CLASS_PARAMSTRACK:
  350. {
  351. try
  352. {
  353. hr = TrackHelpCreateInstance<CParamControlTrack>(pUnknownOuter, iid, ppv);
  354. }
  355. catch( ... )
  356. {
  357. hr = E_OUTOFMEMORY;
  358. }
  359. }
  360. break;
  361. case CLASS_SEGSTATE:
  362. {
  363. CSegState *pInst = new CSegState;
  364. if (pInst == NULL) {
  365. hr = E_OUTOFMEMORY;
  366. break;
  367. }
  368. hr = pInst->QueryInterface(iid, ppv);
  369. pInst->Release();
  370. }
  371. }
  372. return hr;
  373. }
  374. // CClassFactory::LockServer
  375. //
  376. HRESULT __stdcall
  377. CClassFactory::LockServer(BOOL bLock)
  378. {
  379. if (bLock) {
  380. InterlockedIncrement(&g_cLock);
  381. } else {
  382. InterlockedDecrement(&g_cLock);
  383. }
  384. return S_OK;
  385. }
  386. // Version information for our class
  387. //
  388. TCHAR g_szDMPerformanceFriendlyName[] = TEXT("DirectMusicPerformance");
  389. TCHAR g_szDMPerformanceVerIndProgID[] = TEXT("Microsoft.DirectMusicPerformance");
  390. TCHAR g_szDMPerformanceProgID[] = TEXT("Microsoft.DirectMusicPerformance.1");
  391. TCHAR g_szDMSegmentFriendlyName[] = TEXT("DirectMusicSegment");
  392. TCHAR g_szDMSegmentVerIndProgID[] = TEXT("Microsoft.DirectMusicSegment");
  393. TCHAR g_szDMSegmentProgID[] = TEXT("Microsoft.DirectMusicSegment.1");
  394. TCHAR g_szDMSegmentStateFriendlyName[] = TEXT("DirectMusicSegmentState");
  395. TCHAR g_szDMSegmentStateVerIndProgID[] = TEXT("Microsoft.DirectMusicSegmentState");
  396. TCHAR g_szDMSegmentStateProgID[] = TEXT("Microsoft.DirectMusicSegmentState.1");
  397. TCHAR g_szSongFriendlyName[] = TEXT("DirectMusicSong");
  398. TCHAR g_szSongVerIndProgID[] = TEXT("Microsoft.DirectMusicSong");
  399. TCHAR g_szSongProgID[] = TEXT("Microsoft.DirectMusicSong.1");
  400. TCHAR g_szAudioPathFriendlyName[] = TEXT("DirectMusicAudioPath");
  401. TCHAR g_szAudioPathVerIndProgID[] = TEXT("Microsoft.DirectMusicAudioPath");
  402. TCHAR g_szAudioPathProgID[] = TEXT("Microsoft.DirectMusicAudioPath.1");
  403. TCHAR g_szDMGraphFriendlyName[] = TEXT("DirectMusicGraph");
  404. TCHAR g_szDMGraphVerIndProgID[] = TEXT("Microsoft.DirectMusicGraph");
  405. TCHAR g_szDMGraphProgID[] = TEXT("Microsoft.DirectMusicGraph.1");
  406. TCHAR g_szDMSeqTrackFriendlyName[] = TEXT("DirectMusicSeqTrack");
  407. TCHAR g_szDMSeqTrackVerIndProgID[] = TEXT("Microsoft.DirectMusicSeqTrack");
  408. TCHAR g_szDMSeqTrackProgID[] = TEXT("Microsoft.DirectMusicSeqTrack.1");
  409. TCHAR g_szDMSysExTrackFriendlyName[] = TEXT("DirectMusicSysExTrack");
  410. TCHAR g_szDMSysExTrackVerIndProgID[] = TEXT("Microsoft.DirectMusicSysExTrack");
  411. TCHAR g_szDMSysExTrackProgID[] = TEXT("Microsoft.DirectMusicSysExTrack.1");
  412. TCHAR g_szDMTempoTrackFriendlyName[] = TEXT("DirectMusicTempoTrack");
  413. TCHAR g_szDMTempoTrackVerIndProgID[] = TEXT("Microsoft.DirectMusicTempoTrack");
  414. TCHAR g_szDMTempoTrackProgID[] = TEXT("Microsoft.DirectMusicTempoTrack.1");
  415. TCHAR g_szDMTimeSigTrackFriendlyName[] = TEXT("DirectMusicTimeSigTrack");
  416. TCHAR g_szDMTimeSigTrackVerIndProgID[] = TEXT("Microsoft.DirectMusicTimeSigTrack");
  417. TCHAR g_szDMTimeSigTrackProgID[] = TEXT("Microsoft.DirectMusicTimeSigTrack.1");
  418. TCHAR g_szMarkerTrackFriendlyName[] = TEXT("DirectMusicMarkerTrack");
  419. TCHAR g_szMarkerTrackVerIndProgID[] = TEXT("Microsoft.DirectMusicMarkerTrack");
  420. TCHAR g_szMarkerTrackProgID[] = TEXT("Microsoft.DirectMusicMarkerTrack.1");
  421. TCHAR g_szWaveTrackFriendlyName[] = TEXT("DirectMusicWaveTrack");
  422. TCHAR g_szWaveTrackVerIndProgID[] = TEXT("Microsoft.DirectMusicWaveTrack");
  423. TCHAR g_szWaveTrackProgID[] = TEXT("Microsoft.DirectMusicWaveTrack.1");
  424. TCHAR g_szSegTriggerTrackFriendlyName[] = TEXT("DirectMusicSegTriggerTrack");
  425. TCHAR g_szSegTriggerTrackVerIndProgID[] = TEXT("Microsoft.DirectMusicSegTriggerTrack");
  426. TCHAR g_szSegTriggerTrackProgID[] = TEXT("Microsoft.DirectMusicSegTriggerTrack.1");
  427. TCHAR g_szLyricsTrackFriendlyName[] = TEXT("DirectMusicLyricsTrack");
  428. TCHAR g_szLyricsTrackVerIndProgID[] = TEXT("Microsoft.DirectMusicLyricsTrack");
  429. TCHAR g_szLyricsTrackProgID[] = TEXT("Microsoft.DirectMusicLyricsTrack.1");
  430. TCHAR g_szParamControlTrackFriendlyName[] = TEXT("DirectMusicParamControlTrack");
  431. TCHAR g_szParamControlTrackVerIndProgID[] = TEXT("Microsoft.DirectMusicParamControlTrack");
  432. TCHAR g_szParamControlTrackProgID[] = TEXT("Microsoft.DirectMusicParamControlTrack.1");
  433. //////////////////////////////////////////////////////////////////////
  434. //////////////////////////////////////////////////////////////////////
  435. //////////////////////////////////////////////////////////////////////
  436. // Standard calls needed to be an inproc server
  437. //////////////////////////////////////////////////////////////////////
  438. // DllCanUnloadNow
  439. STDAPI DllCanUnloadNow()
  440. {
  441. if (g_cComponent || g_cLock) {
  442. return S_FALSE;
  443. }
  444. return S_OK;
  445. }
  446. //////////////////////////////////////////////////////////////////////
  447. // DllGetClassObject
  448. STDAPI DllGetClassObject(const CLSID& clsid,
  449. const IID& iid,
  450. void** ppv)
  451. {
  452. IUnknown* pIUnknown = NULL;
  453. DWORD dwTypeID = 0;
  454. if(clsid == CLSID_DirectMusicPerformance)
  455. {
  456. dwTypeID = CLASS_PERFORMANCE;
  457. }
  458. else if(clsid == CLSID_DirectMusicSegment)
  459. {
  460. dwTypeID = CLASS_SEGMENT;
  461. }
  462. else if(clsid == CLSID_DirectMusicSong)
  463. {
  464. dwTypeID = CLASS_SONG;
  465. }
  466. else if(clsid == CLSID_DirectMusicAudioPathConfig)
  467. {
  468. dwTypeID = CLASS_AUDIOPATH;
  469. }
  470. else if(clsid == CLSID_DirectMusicSeqTrack)
  471. {
  472. dwTypeID = CLASS_SEQTRACK;
  473. }
  474. else if(clsid == CLSID_DirectMusicGraph)
  475. {
  476. dwTypeID = CLASS_GRAPH;
  477. }
  478. else if(clsid == CLSID_DirectMusicSysExTrack)
  479. {
  480. dwTypeID = CLASS_SYSEXTRACK;
  481. }
  482. else if(clsid == CLSID_DirectMusicTempoTrack)
  483. {
  484. dwTypeID = CLASS_TEMPOTRACK;
  485. }
  486. else if(clsid == CLSID_DirectMusicTimeSigTrack)
  487. {
  488. dwTypeID = CLASS_TIMESIGTRACK;
  489. }
  490. else if(clsid == CLSID_DirectMusicMarkerTrack)
  491. {
  492. dwTypeID = CLASS_MARKERTRACK;
  493. }
  494. else if(clsid == CLSID_DirectMusicWaveTrack)
  495. {
  496. dwTypeID = CLASS_WAVETRACK;
  497. }
  498. else if(clsid == CLSID_DirectMusicSegmentTriggerTrack)
  499. {
  500. dwTypeID = CLASS_TRIGGERTRACK;
  501. }
  502. else if(clsid == CLSID_DirectMusicLyricsTrack)
  503. {
  504. dwTypeID = CLASS_LYRICSTRACK;
  505. }
  506. else if(clsid == CLSID_DirectMusicParamControlTrack)
  507. {
  508. dwTypeID = CLASS_PARAMSTRACK;
  509. }
  510. else if(clsid == CLSID_DirectMusicSegmentState)
  511. {
  512. dwTypeID = CLASS_SEGSTATE;
  513. }
  514. else
  515. {
  516. return CLASS_E_CLASSNOTAVAILABLE;
  517. }
  518. pIUnknown = static_cast<IUnknown*> (new CClassFactory(dwTypeID));
  519. if(pIUnknown)
  520. {
  521. HRESULT hr = pIUnknown->QueryInterface(iid, ppv);
  522. pIUnknown->Release();
  523. return hr;
  524. }
  525. return E_OUTOFMEMORY;
  526. }
  527. //////////////////////////////////////////////////////////////////////
  528. // DllUnregisterServer
  529. STDAPI DllUnregisterServer()
  530. {
  531. UnregisterServer(CLSID_DirectMusicPerformance,
  532. g_szDMPerformanceFriendlyName,
  533. g_szDMPerformanceVerIndProgID,
  534. g_szDMPerformanceProgID);
  535. UnregisterServer(CLSID_DirectMusicSegment,
  536. g_szDMSegmentFriendlyName,
  537. g_szDMSegmentVerIndProgID,
  538. g_szDMSegmentProgID);
  539. UnregisterServer(CLSID_DirectMusicSegmentState,
  540. g_szDMSegmentStateFriendlyName,
  541. g_szDMSegmentStateVerIndProgID,
  542. g_szDMSegmentStateProgID);
  543. UnregisterServer(CLSID_DirectMusicSong,
  544. g_szSongFriendlyName,
  545. g_szSongVerIndProgID,
  546. g_szSongProgID);
  547. UnregisterServer(CLSID_DirectMusicAudioPathConfig,
  548. g_szAudioPathFriendlyName,
  549. g_szAudioPathVerIndProgID,
  550. g_szAudioPathProgID);
  551. UnregisterServer(CLSID_DirectMusicGraph,
  552. g_szDMGraphFriendlyName,
  553. g_szDMGraphVerIndProgID,
  554. g_szDMGraphProgID);
  555. UnregisterServer(CLSID_DirectMusicSeqTrack,
  556. g_szDMSeqTrackFriendlyName,
  557. g_szDMSeqTrackVerIndProgID,
  558. g_szDMSeqTrackProgID);
  559. UnregisterServer(CLSID_DirectMusicSysExTrack,
  560. g_szDMSysExTrackFriendlyName,
  561. g_szDMSysExTrackVerIndProgID,
  562. g_szDMSysExTrackProgID);
  563. UnregisterServer(CLSID_DirectMusicTempoTrack,
  564. g_szDMTempoTrackFriendlyName,
  565. g_szDMTempoTrackVerIndProgID,
  566. g_szDMTempoTrackProgID);
  567. UnregisterServer(CLSID_DirectMusicTimeSigTrack,
  568. g_szDMTimeSigTrackFriendlyName,
  569. g_szDMTimeSigTrackVerIndProgID,
  570. g_szDMTimeSigTrackProgID);
  571. UnregisterServer(CLSID_DirectMusicMarkerTrack,
  572. g_szMarkerTrackFriendlyName,
  573. g_szMarkerTrackVerIndProgID,
  574. g_szMarkerTrackProgID);
  575. UnregisterServer(CLSID_DirectMusicWaveTrack,
  576. g_szWaveTrackFriendlyName,
  577. g_szWaveTrackVerIndProgID,
  578. g_szWaveTrackProgID);
  579. UnregisterServer(CLSID_DirectMusicSegmentTriggerTrack,
  580. g_szSegTriggerTrackFriendlyName,
  581. g_szSegTriggerTrackVerIndProgID,
  582. g_szSegTriggerTrackProgID);
  583. UnregisterServer(CLSID_DirectMusicLyricsTrack,
  584. g_szLyricsTrackFriendlyName,
  585. g_szLyricsTrackVerIndProgID,
  586. g_szLyricsTrackProgID);
  587. UnregisterServer(CLSID_DirectMusicParamControlTrack,
  588. g_szParamControlTrackFriendlyName,
  589. g_szParamControlTrackVerIndProgID,
  590. g_szParamControlTrackProgID);
  591. return S_OK;
  592. }
  593. //////////////////////////////////////////////////////////////////////
  594. // DllRegisterServer
  595. STDAPI DllRegisterServer()
  596. {
  597. RegisterServer(g_hModule,
  598. CLSID_DirectMusicPerformance,
  599. g_szDMPerformanceFriendlyName,
  600. g_szDMPerformanceVerIndProgID,
  601. g_szDMPerformanceProgID);
  602. RegisterServer(g_hModule,
  603. CLSID_DirectMusicSegment,
  604. g_szDMSegmentFriendlyName,
  605. g_szDMSegmentVerIndProgID,
  606. g_szDMSegmentProgID);
  607. RegisterServer(g_hModule,
  608. CLSID_DirectMusicSegmentState,
  609. g_szDMSegmentStateFriendlyName,
  610. g_szDMSegmentStateVerIndProgID,
  611. g_szDMSegmentStateProgID);
  612. RegisterServer(g_hModule,
  613. CLSID_DirectMusicSong,
  614. g_szSongFriendlyName,
  615. g_szSongVerIndProgID,
  616. g_szSongProgID);
  617. RegisterServer(g_hModule,
  618. CLSID_DirectMusicAudioPathConfig,
  619. g_szAudioPathFriendlyName,
  620. g_szAudioPathVerIndProgID,
  621. g_szAudioPathProgID);
  622. RegisterServer(g_hModule,
  623. CLSID_DirectMusicGraph,
  624. g_szDMGraphFriendlyName,
  625. g_szDMGraphVerIndProgID,
  626. g_szDMGraphProgID);
  627. RegisterServer(g_hModule,
  628. CLSID_DirectMusicSeqTrack,
  629. g_szDMSeqTrackFriendlyName,
  630. g_szDMSeqTrackVerIndProgID,
  631. g_szDMSeqTrackProgID);
  632. RegisterServer(g_hModule,
  633. CLSID_DirectMusicSysExTrack,
  634. g_szDMSysExTrackFriendlyName,
  635. g_szDMSysExTrackVerIndProgID,
  636. g_szDMSysExTrackProgID);
  637. RegisterServer(g_hModule,
  638. CLSID_DirectMusicTempoTrack,
  639. g_szDMTempoTrackFriendlyName,
  640. g_szDMTempoTrackVerIndProgID,
  641. g_szDMTempoTrackProgID);
  642. RegisterServer(g_hModule,
  643. CLSID_DirectMusicTimeSigTrack,
  644. g_szDMTimeSigTrackFriendlyName,
  645. g_szDMTimeSigTrackVerIndProgID,
  646. g_szDMTimeSigTrackProgID);
  647. RegisterServer(g_hModule,
  648. CLSID_DirectMusicMarkerTrack,
  649. g_szMarkerTrackFriendlyName,
  650. g_szMarkerTrackVerIndProgID,
  651. g_szMarkerTrackProgID);
  652. RegisterServer(g_hModule,
  653. CLSID_DirectMusicWaveTrack,
  654. g_szWaveTrackFriendlyName,
  655. g_szWaveTrackVerIndProgID,
  656. g_szWaveTrackProgID);
  657. RegisterServer(g_hModule,
  658. CLSID_DirectMusicSegmentTriggerTrack,
  659. g_szSegTriggerTrackFriendlyName,
  660. g_szSegTriggerTrackVerIndProgID,
  661. g_szSegTriggerTrackProgID);
  662. RegisterServer(g_hModule,
  663. CLSID_DirectMusicLyricsTrack,
  664. g_szLyricsTrackFriendlyName,
  665. g_szLyricsTrackVerIndProgID,
  666. g_szLyricsTrackProgID);
  667. RegisterServer(g_hModule,
  668. CLSID_DirectMusicParamControlTrack,
  669. g_szParamControlTrackFriendlyName,
  670. g_szParamControlTrackVerIndProgID,
  671. g_szParamControlTrackProgID);
  672. return S_OK;
  673. }
  674. //////////////////////////////////////////////////////////////////////
  675. // Standard Win32 DllMain
  676. //////////////////////////////////////////////////////////////////////
  677. // DllMain
  678. #ifdef DBG
  679. static char* aszReasons[] =
  680. {
  681. "DLL_PROCESS_DETACH",
  682. "DLL_PROCESS_ATTACH",
  683. "DLL_THREAD_ATTACH",
  684. "DLL_THREAD_DETACH"
  685. };
  686. const DWORD nReasons = (sizeof(aszReasons) / sizeof(char*));
  687. #endif
  688. BOOL APIENTRY DllMain(HINSTANCE hModule,
  689. DWORD dwReason,
  690. void *lpReserved)
  691. {
  692. static int nReferenceCount = 0;
  693. #ifdef DBG
  694. if (dwReason < nReasons)
  695. {
  696. TraceI(0, "DllMain: %s\n", (LPSTR)aszReasons[dwReason]);
  697. }
  698. else
  699. {
  700. TraceI(0, "DllMain: Unknown dwReason <%u>\n", dwReason);
  701. }
  702. #endif
  703. switch(dwReason)
  704. {
  705. case DLL_PROCESS_ATTACH:
  706. if (++nReferenceCount == 1)
  707. {
  708. g_fInitCS = false;
  709. try
  710. {
  711. InitializeCriticalSection(&g_CritSec);
  712. InitializeCriticalSection(&WaveItem::st_WaveListCritSect);
  713. }
  714. catch( ... )
  715. {
  716. TraceI(0, "InitializeCriticalSection failed.\n");
  717. return FALSE;
  718. }
  719. g_fInitCS = true;
  720. #ifdef DBG
  721. DebugInit();
  722. #endif
  723. if (!DisableThreadLibraryCalls(hModule))
  724. {
  725. TraceI(1, "DisableThreadLibraryCalls failed.\n");
  726. }
  727. g_hModule = hModule;
  728. }
  729. break;
  730. case DLL_PROCESS_DETACH:
  731. if (--nReferenceCount == 0)
  732. {
  733. TraceI(-1, "Unloading g_cLock %d g_cComponent %d\n", g_cLock, g_cComponent);
  734. if (g_fInitCS)
  735. {
  736. DeleteCriticalSection(&g_CritSec);
  737. DeleteCriticalSection(&WaveItem::st_WaveListCritSect);
  738. }
  739. // Assert if we still have some objects hanging around
  740. assert(g_cComponent == 0);
  741. assert(g_cLock == 0);
  742. }
  743. break;
  744. }
  745. return TRUE;
  746. }