Source code of Windows XP (NT5)
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.

564 lines
13 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dmloaderobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // dmLoaderObj.cpp
  11. #include "stdafx.h"
  12. #include "Direct.h"
  13. #include "dmusici.h"
  14. #include "dms.h"
  15. #include "dmLoaderObj.h"
  16. #include "dmBandObj.h"
  17. #include "dmSegmentObj.h"
  18. #include "dmStyleObj.h"
  19. #include "dmCollectionObj.h"
  20. #include "dmChordMapObj.h"
  21. extern void *g_dxj_DirectMusicLoader;
  22. extern void *g_dxj_DirectMusicBand;
  23. extern void *g_dxj_DirectMusicStyle;
  24. extern void *g_dxj_DirectMusicSegment;
  25. extern void *g_dxj_DirectMusicCollection;
  26. extern void *g_dxj_DirectMusicChordMap;
  27. CONSTRUCTOR(_dxj_DirectMusicLoader, {});
  28. DESTRUCTOR(_dxj_DirectMusicLoader, {});
  29. GETSET_OBJECT(_dxj_DirectMusicLoader);
  30. extern HRESULT CREATE_DMSEGMENT_NOADDREF(IDirectMusicSegment *pSeg,I_dxj_DirectMusicSegment **segment) ;
  31. BOOL HasBackslash(BSTR b){
  32. DWORD cbLen=SysStringLen(b);
  33. for (DWORD i=0;i<cbLen;i++)
  34. {
  35. if (b[i]==((unsigned short)'\\'))
  36. return TRUE;
  37. }
  38. return FALSE;
  39. }
  40. HRESULT C_dxj_DirectMusicLoaderObject::loadSegment(
  41. /* [in] */ BSTR filename,
  42. /* [retval][out] */ I_dxj_DirectMusicSegment __RPC_FAR *__RPC_FAR *ret)
  43. {
  44. HRESULT hr;
  45. if (!filename) return E_INVALIDARG;
  46. if (!ret) return E_INVALIDARG;
  47. DMUS_OBJECTDESC objdesc;
  48. ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  49. objdesc.dwSize=sizeof(DMUS_OBJECTDESC);
  50. objdesc.dwValidData=DMUS_OBJ_FILENAME | DMUS_OBJ_CLASS ; //DMUS_OBJ_FULLPATH
  51. objdesc.guidClass=CLSID_DirectMusicSegment;
  52. if (((DWORD*)filename)[-1]>DMUS_MAX_FILENAME) return E_INVALIDARG;
  53. wcscpy(objdesc.wszFileName, filename);
  54. IDirectMusicSegment *pOut=NULL;
  55. if (HasBackslash(filename)){
  56. objdesc.dwValidData=objdesc.dwValidData | DMUS_OBJ_FULLPATH;
  57. }
  58. hr=m__dxj_DirectMusicLoader->GetObject(&objdesc,IID_IDirectMusicSegment,(void**)&pOut);
  59. if FAILED(hr) return hr;
  60. if (!pOut)return E_OUTOFMEMORY;
  61. //INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicSegment,pOut,ret);
  62. hr=CREATE_DMSEGMENT_NOADDREF(pOut,ret);
  63. if FAILED(hr) return hr;
  64. if (!*ret)return E_OUTOFMEMORY;
  65. return hr;
  66. }
  67. HRESULT C_dxj_DirectMusicLoaderObject::loadStyle(
  68. /* [in] */ BSTR filename,
  69. /* [retval][out] */ I_dxj_DirectMusicStyle __RPC_FAR *__RPC_FAR *ret)
  70. {
  71. HRESULT hr;
  72. if (!filename) return E_INVALIDARG;
  73. if (!ret) return E_INVALIDARG;
  74. DMUS_OBJECTDESC objdesc;
  75. ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  76. objdesc.dwSize=sizeof(DMUS_OBJECTDESC);
  77. objdesc.dwValidData=DMUS_OBJ_FILENAME | DMUS_OBJ_CLASS ;
  78. objdesc.guidClass=CLSID_DirectMusicStyle;
  79. if (((DWORD*)filename)[-1]>DMUS_MAX_FILENAME) return E_INVALIDARG;
  80. wcscpy(objdesc.wszFileName, filename);
  81. IDirectMusicSegment *pOut=NULL;
  82. if (HasBackslash(filename)){
  83. objdesc.dwValidData=objdesc.dwValidData | DMUS_OBJ_FULLPATH;
  84. }
  85. hr=m__dxj_DirectMusicLoader->GetObject(&objdesc,IID_IDirectMusicStyle,(void**)&pOut);
  86. if FAILED(hr) return hr;
  87. if (!pOut)return E_OUTOFMEMORY;
  88. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicStyle,pOut,ret);
  89. if (!*ret)return E_OUTOFMEMORY;
  90. return hr;
  91. }
  92. HRESULT C_dxj_DirectMusicLoaderObject::loadBand(
  93. /* [in] */ BSTR filename,
  94. /* [retval][out] */ I_dxj_DirectMusicBand __RPC_FAR *__RPC_FAR *ret)
  95. {
  96. HRESULT hr;
  97. if (!filename) return E_INVALIDARG;
  98. if (!ret) return E_INVALIDARG;
  99. DMUS_OBJECTDESC objdesc;
  100. ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  101. objdesc.dwSize=sizeof(DMUS_OBJECTDESC);
  102. objdesc.dwValidData=DMUS_OBJ_FILENAME | DMUS_OBJ_CLASS ;
  103. objdesc.guidClass=CLSID_DirectMusicBand;
  104. if (((DWORD*)filename)[-1]>DMUS_MAX_FILENAME) return E_INVALIDARG;
  105. wcscpy(objdesc.wszFileName, filename);
  106. IDirectMusicSegment *pOut=NULL;
  107. if (HasBackslash(filename)){
  108. objdesc.dwValidData=objdesc.dwValidData | DMUS_OBJ_FULLPATH;
  109. }
  110. hr=m__dxj_DirectMusicLoader->GetObject(&objdesc,IID_IDirectMusicBand,(void**)&pOut);
  111. if FAILED(hr) return hr;
  112. if (!pOut)return E_OUTOFMEMORY;
  113. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicBand,pOut,ret);
  114. if (!*ret)return E_OUTOFMEMORY;
  115. return hr;
  116. }
  117. HRESULT C_dxj_DirectMusicLoaderObject::loadCollection(
  118. /* [in] */ BSTR filename,
  119. /* [retval][out] */ I_dxj_DirectMusicCollection __RPC_FAR *__RPC_FAR *ret)
  120. {
  121. HRESULT hr;
  122. if (!filename) return E_INVALIDARG;
  123. if (!ret) return E_INVALIDARG;
  124. DMUS_OBJECTDESC objdesc;
  125. ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  126. objdesc.dwSize=sizeof(DMUS_OBJECTDESC);
  127. objdesc.dwValidData=DMUS_OBJ_FILENAME | DMUS_OBJ_CLASS ;
  128. objdesc.guidClass=CLSID_DirectMusicCollection;
  129. if (((DWORD*)filename)[-1]>DMUS_MAX_FILENAME) return E_INVALIDARG;
  130. wcscpy(objdesc.wszFileName, filename);
  131. IDirectMusicSegment *pOut=NULL;
  132. if (HasBackslash(filename)){
  133. objdesc.dwValidData=objdesc.dwValidData | DMUS_OBJ_FULLPATH;
  134. }
  135. hr=m__dxj_DirectMusicLoader->GetObject(&objdesc,IID_IDirectMusicCollection,(void**)&pOut);
  136. if FAILED(hr) return hr;
  137. if (!pOut)return E_OUTOFMEMORY;
  138. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicCollection,pOut,ret);
  139. if (!*ret)return E_OUTOFMEMORY;
  140. return hr;
  141. }
  142. HRESULT C_dxj_DirectMusicLoaderObject::loadChordMap(
  143. /* [in] */ BSTR filename,
  144. /* [retval][out] */ I_dxj_DirectMusicChordMap __RPC_FAR *__RPC_FAR *ret)
  145. {
  146. HRESULT hr;
  147. if (!filename) return E_INVALIDARG;
  148. if (!ret) return E_INVALIDARG;
  149. DMUS_OBJECTDESC objdesc;
  150. ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  151. objdesc.dwSize=sizeof(DMUS_OBJECTDESC);
  152. objdesc.dwValidData=DMUS_OBJ_FILENAME | DMUS_OBJ_CLASS ;
  153. objdesc.guidClass=CLSID_DirectMusicChordMap;
  154. if (((DWORD*)filename)[-1]>DMUS_MAX_FILENAME) return E_INVALIDARG;
  155. wcscpy(objdesc.wszFileName, filename);
  156. IDirectMusicSegment *pOut=NULL;
  157. if (HasBackslash(filename)){
  158. objdesc.dwValidData=objdesc.dwValidData | DMUS_OBJ_FULLPATH;
  159. }
  160. hr=m__dxj_DirectMusicLoader->GetObject(&objdesc,IID_IDirectMusicChordMap,(void**)&pOut);
  161. if FAILED(hr) return hr;
  162. if (!pOut)return E_OUTOFMEMORY;
  163. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicChordMap,pOut,ret);
  164. if (!*ret)return E_OUTOFMEMORY;
  165. return hr;
  166. }
  167. HRESULT STDMETHODCALLTYPE C_dxj_DirectMusicLoaderObject::loadSegmentFromResource(
  168. /* [in] */ BSTR moduleName,
  169. /* [in] */ BSTR resourceName,
  170. /* [retval][out] */ I_dxj_DirectMusicSegment __RPC_FAR *__RPC_FAR *ret)
  171. {
  172. HRESULT hr;
  173. HRSRC hres=NULL;
  174. HGLOBAL hglob=NULL;
  175. void *pMem=NULL;
  176. DWORD dwSize=0;
  177. if (!resourceName) return E_INVALIDARG;
  178. if (!ret) return E_INVALIDARG;
  179. HMODULE hMod=NULL;
  180. USES_CONVERSION;
  181. if ((moduleName) &&(moduleName[0]!=0)){
  182. // NOTE
  183. // seems that GetModuleHandleW is
  184. // always returning 0 on w98
  185. // so we convert to ansi first
  186. LPCTSTR pszName = W2T(moduleName);
  187. hMod= GetModuleHandle(pszName);
  188. }
  189. hres=FindResourceW(hMod,resourceName,(LPWSTR)L"DMSEG");
  190. if (!hres) return E_FAIL;
  191. pMem=(void*)LoadResource(hMod,hres);
  192. if (!pMem) return E_FAIL;
  193. dwSize=SizeofResource(hMod,hres);
  194. DMUS_OBJECTDESC objdesc;
  195. ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  196. objdesc.dwSize=sizeof(DMUS_OBJECTDESC);
  197. objdesc.dwValidData=DMUS_OBJ_MEMORY | DMUS_OBJ_CLASS ;
  198. objdesc.guidClass=CLSID_DirectMusicSegment;
  199. objdesc.llMemLength =(LONGLONG)dwSize;
  200. objdesc.pbMemData =(BYTE*)pMem;
  201. IDirectMusicSegment *pOut=NULL;
  202. hr=m__dxj_DirectMusicLoader->GetObject(&objdesc,IID_IDirectMusicSegment,(void**)&pOut);
  203. if FAILED(hr) return hr;
  204. if (!pOut)return E_OUTOFMEMORY;
  205. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicSegment,pOut,ret);
  206. if (!*ret)return E_OUTOFMEMORY;
  207. return hr;
  208. }
  209. HRESULT STDMETHODCALLTYPE C_dxj_DirectMusicLoaderObject::loadStyleFromResource(
  210. /* [in] */ BSTR moduleName,
  211. /* [in] */ BSTR resourceName,
  212. /* [retval][out] */ I_dxj_DirectMusicStyle __RPC_FAR *__RPC_FAR *ret)
  213. {
  214. HRESULT hr;
  215. HRSRC hres=NULL;
  216. HGLOBAL hglob=NULL;
  217. void *pMem=NULL;
  218. DWORD dwSize=0;
  219. if (!resourceName) return E_INVALIDARG;
  220. if (!ret) return E_INVALIDARG;
  221. HMODULE hMod=NULL;
  222. USES_CONVERSION;
  223. if ((moduleName) &&(moduleName[0]!=0)){
  224. // NOTE
  225. // seems that GetModuleHandleW is
  226. // always returning 0 on w98
  227. // convert to ansi first
  228. LPCTSTR pszName = W2T(moduleName);
  229. hMod= GetModuleHandle(pszName);
  230. }
  231. hres=FindResourceW(hMod,resourceName,(LPWSTR)L"DMSTYLE");
  232. if (!hres) return E_FAIL;
  233. pMem=(void*)LoadResource(hMod,hres);
  234. if (!pMem) return E_FAIL;
  235. dwSize=SizeofResource(hMod,hres);
  236. DMUS_OBJECTDESC objdesc;
  237. ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  238. objdesc.dwSize=sizeof(DMUS_OBJECTDESC);
  239. objdesc.dwValidData=DMUS_OBJ_MEMORY | DMUS_OBJ_CLASS ;
  240. objdesc.guidClass=CLSID_DirectMusicStyle;
  241. objdesc.llMemLength =(LONGLONG)dwSize;
  242. objdesc.pbMemData =(BYTE*)pMem;
  243. IDirectMusicSegment *pOut=NULL;
  244. hr=m__dxj_DirectMusicLoader->GetObject(&objdesc,IID_IDirectMusicStyle,(void**)&pOut);
  245. if FAILED(hr) return hr;
  246. if (!pOut)return E_OUTOFMEMORY;
  247. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicStyle,pOut,ret);
  248. if (!*ret)return E_OUTOFMEMORY;
  249. return hr;
  250. }
  251. HRESULT STDMETHODCALLTYPE C_dxj_DirectMusicLoaderObject::loadBandFromResource(
  252. /* [in] */ BSTR moduleName,
  253. /* [in] */ BSTR resourceName,
  254. /* [retval][out] */ I_dxj_DirectMusicBand __RPC_FAR *__RPC_FAR *ret)
  255. {
  256. HRESULT hr;
  257. HRSRC hres=NULL;
  258. HGLOBAL hglob=NULL;
  259. void *pMem=NULL;
  260. DWORD dwSize=0;
  261. if (!resourceName) return E_INVALIDARG;
  262. if (!ret) return E_INVALIDARG;
  263. HMODULE hMod=NULL;
  264. USES_CONVERSION;
  265. if ((moduleName) &&(moduleName[0]!=0)){
  266. // NOTE
  267. // seems that GetModuleHandleW is
  268. // always returning 0 on w98
  269. // converting to ansi first
  270. LPCTSTR pszName = W2T(moduleName);
  271. hMod= GetModuleHandle(pszName);
  272. }
  273. hres=FindResourceW(hMod,resourceName,(LPWSTR)L"DMBAND");
  274. if (!hres) return E_FAIL;
  275. pMem=(void*)LoadResource(hMod,hres);
  276. if (!pMem) return E_FAIL;
  277. dwSize=SizeofResource(hMod,hres);
  278. DMUS_OBJECTDESC objdesc;
  279. ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  280. objdesc.dwSize=sizeof(DMUS_OBJECTDESC);
  281. objdesc.dwValidData=DMUS_OBJ_MEMORY | DMUS_OBJ_CLASS ;
  282. objdesc.guidClass=CLSID_DirectMusicBand;
  283. objdesc.llMemLength =(LONGLONG)dwSize;
  284. objdesc.pbMemData =(BYTE*)pMem;
  285. IDirectMusicSegment *pOut=NULL;
  286. hr=m__dxj_DirectMusicLoader->GetObject(&objdesc,IID_IDirectMusicBand,(void**)&pOut);
  287. if FAILED(hr) return hr;
  288. if (!pOut)return E_OUTOFMEMORY;
  289. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicBand,pOut,ret);
  290. if (!*ret)return E_OUTOFMEMORY;
  291. return hr;
  292. }
  293. HRESULT STDMETHODCALLTYPE C_dxj_DirectMusicLoaderObject::loadCollectionFromResource(
  294. /* [in] */ BSTR moduleName,
  295. /* [in] */ BSTR resourceName,
  296. /* [retval][out] */ I_dxj_DirectMusicCollection __RPC_FAR *__RPC_FAR *ret)
  297. {
  298. HRESULT hr;
  299. HRSRC hres=NULL;
  300. HGLOBAL hglob=NULL;
  301. void *pMem=NULL;
  302. DWORD dwSize=0;
  303. if (!resourceName) return E_INVALIDARG;
  304. if (!ret) return E_INVALIDARG;
  305. HMODULE hMod=NULL;
  306. USES_CONVERSION;
  307. if ((moduleName) &&(moduleName[0]!=0)){
  308. // NOTE
  309. // seems that GetModuleHandleW is
  310. // always returning 0 on w98
  311. // converting to ansi first
  312. LPCTSTR pszName = W2T(moduleName);
  313. hMod= GetModuleHandle(pszName);
  314. }
  315. hres=FindResourceW(hMod,resourceName,(LPWSTR)L"DMCOL");
  316. if (!hres) return E_FAIL;
  317. pMem=(void*)LoadResource(hMod,hres);
  318. if (!pMem) return E_FAIL;
  319. dwSize=SizeofResource(hMod,hres);
  320. DMUS_OBJECTDESC objdesc;
  321. ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  322. objdesc.dwSize=sizeof(DMUS_OBJECTDESC);
  323. objdesc.dwValidData=DMUS_OBJ_MEMORY | DMUS_OBJ_CLASS ;
  324. objdesc.guidClass=CLSID_DirectMusicCollection;
  325. objdesc.llMemLength =(LONGLONG)dwSize;
  326. objdesc.pbMemData =(BYTE*)pMem;
  327. IDirectMusicSegment *pOut=NULL;
  328. hr=m__dxj_DirectMusicLoader->GetObject(&objdesc,IID_IDirectMusicCollection,(void**)&pOut);
  329. if FAILED(hr) return hr;
  330. if (!pOut)return E_OUTOFMEMORY;
  331. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicCollection,pOut,ret);
  332. if (!*ret)return E_OUTOFMEMORY;
  333. return hr;
  334. }
  335. HRESULT STDMETHODCALLTYPE C_dxj_DirectMusicLoaderObject::loadChordMapFromResource(
  336. /* [in] */ BSTR moduleName,
  337. /* [in] */ BSTR resourceName,
  338. /* [retval][out] */ I_dxj_DirectMusicChordMap __RPC_FAR *__RPC_FAR *ret)
  339. {
  340. HRESULT hr;
  341. HRSRC hres=NULL;
  342. HGLOBAL hglob=NULL;
  343. void *pMem=NULL;
  344. DWORD dwSize=0;
  345. if (!resourceName) return E_INVALIDARG;
  346. if (!ret) return E_INVALIDARG;
  347. HMODULE hMod=NULL;
  348. USES_CONVERSION;
  349. if ((moduleName) &&(moduleName[0]!=0)){
  350. // NOTE
  351. // seems that GetModuleHandleW is
  352. // always returning 0 on w98??
  353. // converting to ansi first
  354. LPCTSTR pszName = W2T(moduleName);
  355. hMod= GetModuleHandle(pszName);
  356. }
  357. hres=FindResourceW(hMod,resourceName,(LPWSTR)L"DMCHORD");
  358. if (!hres) {
  359. //MessageBox(NULL,"FindResourceW Failed","test",MB_OK);
  360. return E_FAIL;
  361. }
  362. pMem=(void*)LoadResource(hMod,hres);
  363. if (!pMem){
  364. //MessageBox(NULL,"LoadResource Failed","test",MB_OK);
  365. return E_FAIL;
  366. }
  367. dwSize=SizeofResource(hMod,hres);
  368. DMUS_OBJECTDESC objdesc;
  369. ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  370. objdesc.dwSize=sizeof(DMUS_OBJECTDESC);
  371. objdesc.dwValidData=DMUS_OBJ_MEMORY | DMUS_OBJ_CLASS ;
  372. objdesc.guidClass=CLSID_DirectMusicChordMap;
  373. objdesc.llMemLength =(LONGLONG)dwSize;
  374. objdesc.pbMemData =(BYTE*)pMem;
  375. IDirectMusicSegment *pOut=NULL;
  376. hr=m__dxj_DirectMusicLoader->GetObject(&objdesc,IID_IDirectMusicChordMap,(void**)&pOut);
  377. if FAILED(hr) {
  378. //MessageBox(NULL,"GetObject Failed","test",MB_OK);
  379. return hr;
  380. }
  381. if (!pOut)return E_OUTOFMEMORY;
  382. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicChordMap,pOut,ret);
  383. if (!*ret)return E_OUTOFMEMORY;
  384. return hr;
  385. }
  386. HRESULT STDMETHODCALLTYPE C_dxj_DirectMusicLoaderObject::setSearchDirectory( BSTR dir)
  387. {
  388. HRESULT hr;
  389. hr=m__dxj_DirectMusicLoader->SetSearchDirectory(GUID_DirectMusicAllTypes,dir, TRUE); //?
  390. return hr;
  391. }