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.

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