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.

544 lines
14 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 = NULL;
  166. __try { pszName = W2T(moduleName); } __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  167. hMod= GetModuleHandle(pszName);
  168. }
  169. hres=FindResourceW(hMod,resourceName,(LPWSTR)L"DMSEG");
  170. if (!hres) return E_FAIL;
  171. pMem=(void*)LoadResource(hMod,hres);
  172. if (!pMem) return E_FAIL;
  173. dwSize=SizeofResource(hMod,hres);
  174. DMUS_OBJECTDESC objdesc;
  175. ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  176. objdesc.dwSize=sizeof(DMUS_OBJECTDESC);
  177. objdesc.dwValidData=DMUS_OBJ_MEMORY | DMUS_OBJ_CLASS ;
  178. objdesc.guidClass=CLSID_DirectMusicSegment;
  179. objdesc.llMemLength =(LONGLONG)dwSize;
  180. objdesc.pbMemData =(BYTE*)pMem;
  181. IDirectMusicSegment8 *pOut=NULL;
  182. hr=m__dxj_DirectMusicLoader->GetObject(&objdesc,IID_IDirectMusicSegment8,(void**)&pOut);
  183. if FAILED(hr) return hr;
  184. if (!pOut)return E_OUTOFMEMORY;
  185. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicSegment,pOut,ret);
  186. if (!*ret)return E_OUTOFMEMORY;
  187. return hr;
  188. }
  189. HRESULT STDMETHODCALLTYPE C_dxj_DirectMusicLoaderObject::loadStyleFromResource(
  190. /* [in] */ BSTR moduleName,
  191. /* [in] */ BSTR resourceName,
  192. /* [retval][out] */ I_dxj_DirectMusicStyle __RPC_FAR *__RPC_FAR *ret)
  193. {
  194. HRESULT hr;
  195. HRSRC hres=NULL;
  196. HGLOBAL hglob=NULL;
  197. void *pMem=NULL;
  198. DWORD dwSize=0;
  199. if (!resourceName) return E_INVALIDARG;
  200. if (!ret) return E_INVALIDARG;
  201. HMODULE hMod=NULL;
  202. USES_CONVERSION;
  203. if ((moduleName) &&(moduleName[0]!=0)){
  204. // NOTE: -
  205. // seems that GetModuleHandleW is
  206. // always returning 0 on w98??
  207. // hMod= GetModuleHandleW(moduleName);
  208. LPCTSTR pszName = NULL;
  209. __try { pszName = W2T(moduleName); } __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  210. hMod= GetModuleHandle(pszName);
  211. }
  212. hres=FindResourceW(hMod,resourceName,(LPWSTR)L"DMSTYLE");
  213. if (!hres) return E_FAIL;
  214. pMem=(void*)LoadResource(hMod,hres);
  215. if (!pMem) return E_FAIL;
  216. dwSize=SizeofResource(hMod,hres);
  217. DMUS_OBJECTDESC objdesc;
  218. ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  219. objdesc.dwSize=sizeof(DMUS_OBJECTDESC);
  220. objdesc.dwValidData=DMUS_OBJ_MEMORY | DMUS_OBJ_CLASS ;
  221. objdesc.guidClass=CLSID_DirectMusicStyle;
  222. objdesc.llMemLength =(LONGLONG)dwSize;
  223. objdesc.pbMemData =(BYTE*)pMem;
  224. IDirectMusicSegment8 *pOut=NULL;
  225. hr=m__dxj_DirectMusicLoader->GetObject(&objdesc,IID_IDirectMusicStyle8,(void**)&pOut);
  226. if FAILED(hr) return hr;
  227. if (!pOut)return E_OUTOFMEMORY;
  228. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicStyle,pOut,ret);
  229. if (!*ret)return E_OUTOFMEMORY;
  230. return hr;
  231. }
  232. HRESULT STDMETHODCALLTYPE C_dxj_DirectMusicLoaderObject::loadBandFromResource(
  233. /* [in] */ BSTR moduleName,
  234. /* [in] */ BSTR resourceName,
  235. /* [retval][out] */ I_dxj_DirectMusicBand __RPC_FAR *__RPC_FAR *ret)
  236. {
  237. HRESULT hr;
  238. HRSRC hres=NULL;
  239. HGLOBAL hglob=NULL;
  240. void *pMem=NULL;
  241. DWORD dwSize=0;
  242. if (!resourceName) return E_INVALIDARG;
  243. if (!ret) return E_INVALIDARG;
  244. HMODULE hMod=NULL;
  245. USES_CONVERSION;
  246. if ((moduleName) &&(moduleName[0]!=0)){
  247. // NOTE: -
  248. // seems that GetModuleHandleW is
  249. // always returning 0 on w98??
  250. // hMod= GetModuleHandleW(moduleName);
  251. LPCTSTR pszName = NULL;
  252. __try { pszName = W2T(moduleName); } __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  253. hMod= GetModuleHandle(pszName);
  254. }
  255. hres=FindResourceW(hMod,resourceName,(LPWSTR)L"DMBAND");
  256. if (!hres) return E_FAIL;
  257. pMem=(void*)LoadResource(hMod,hres);
  258. if (!pMem) return E_FAIL;
  259. dwSize=SizeofResource(hMod,hres);
  260. DMUS_OBJECTDESC objdesc;
  261. ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  262. objdesc.dwSize=sizeof(DMUS_OBJECTDESC);
  263. objdesc.dwValidData=DMUS_OBJ_MEMORY | DMUS_OBJ_CLASS ;
  264. objdesc.guidClass=CLSID_DirectMusicBand;
  265. objdesc.llMemLength =(LONGLONG)dwSize;
  266. objdesc.pbMemData =(BYTE*)pMem;
  267. IDirectMusicSegment8 *pOut=NULL;
  268. hr=m__dxj_DirectMusicLoader->GetObject(&objdesc,IID_IDirectMusicBand8,(void**)&pOut);
  269. if FAILED(hr) return hr;
  270. if (!pOut)return E_OUTOFMEMORY;
  271. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicBand,pOut,ret);
  272. if (!*ret)return E_OUTOFMEMORY;
  273. return hr;
  274. }
  275. HRESULT STDMETHODCALLTYPE C_dxj_DirectMusicLoaderObject::loadCollectionFromResource(
  276. /* [in] */ BSTR moduleName,
  277. /* [in] */ BSTR resourceName,
  278. /* [retval][out] */ I_dxj_DirectMusicCollection __RPC_FAR *__RPC_FAR *ret)
  279. {
  280. HRESULT hr;
  281. HRSRC hres=NULL;
  282. HGLOBAL hglob=NULL;
  283. void *pMem=NULL;
  284. DWORD dwSize=0;
  285. if (!resourceName) return E_INVALIDARG;
  286. if (!ret) return E_INVALIDARG;
  287. HMODULE hMod=NULL;
  288. USES_CONVERSION;
  289. if ((moduleName) &&(moduleName[0]!=0)){
  290. // NOTE: -
  291. // seems that GetModuleHandleW is
  292. // always returning 0 on w98??
  293. // hMod= GetModuleHandleW(moduleName);
  294. LPCTSTR pszName = NULL;
  295. __try { pszName = W2T(moduleName); } __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  296. hMod= GetModuleHandle(pszName);
  297. }
  298. hres=FindResourceW(hMod,resourceName,(LPWSTR)L"DMCOL");
  299. if (!hres) return E_FAIL;
  300. pMem=(void*)LoadResource(hMod,hres);
  301. if (!pMem) return E_FAIL;
  302. dwSize=SizeofResource(hMod,hres);
  303. DMUS_OBJECTDESC objdesc;
  304. ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  305. objdesc.dwSize=sizeof(DMUS_OBJECTDESC);
  306. objdesc.dwValidData=DMUS_OBJ_MEMORY | DMUS_OBJ_CLASS ;
  307. objdesc.guidClass=CLSID_DirectMusicCollection;
  308. objdesc.llMemLength =(LONGLONG)dwSize;
  309. objdesc.pbMemData =(BYTE*)pMem;
  310. IDirectMusicSegment8 *pOut=NULL;
  311. hr=m__dxj_DirectMusicLoader->GetObject(&objdesc,IID_IDirectMusicCollection8,(void**)&pOut);
  312. if FAILED(hr) return hr;
  313. if (!pOut)return E_OUTOFMEMORY;
  314. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicCollection,pOut,ret);
  315. if (!*ret)return E_OUTOFMEMORY;
  316. return hr;
  317. }
  318. HRESULT STDMETHODCALLTYPE C_dxj_DirectMusicLoaderObject::loadChordMapFromResource(
  319. /* [in] */ BSTR moduleName,
  320. /* [in] */ BSTR resourceName,
  321. /* [retval][out] */ I_dxj_DirectMusicChordMap __RPC_FAR *__RPC_FAR *ret)
  322. {
  323. HRESULT hr;
  324. HRSRC hres=NULL;
  325. HGLOBAL hglob=NULL;
  326. void *pMem=NULL;
  327. DWORD dwSize=0;
  328. if (!resourceName) return E_INVALIDARG;
  329. if (!ret) return E_INVALIDARG;
  330. HMODULE hMod=NULL;
  331. USES_CONVERSION;
  332. if ((moduleName) &&(moduleName[0]!=0)){
  333. // NOTE: -
  334. // seems that GetModuleHandleW is
  335. // always returning 0 on w98??
  336. // hMod= GetModuleHandleW(moduleName);
  337. LPCTSTR pszName = NULL;
  338. __try { pszName = W2T(moduleName); } __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  339. hMod= GetModuleHandle(pszName);
  340. }
  341. hres=FindResourceW(hMod,resourceName,(LPWSTR)L"DMCHORD");
  342. if (!hres) {
  343. //MessageBox(NULL,"FindResourceW Failed","test",MB_OK);
  344. return E_FAIL;
  345. }
  346. pMem=(void*)LoadResource(hMod,hres);
  347. if (!pMem){
  348. //MessageBox(NULL,"LoadResource Failed","test",MB_OK);
  349. return E_FAIL;
  350. }
  351. dwSize=SizeofResource(hMod,hres);
  352. DMUS_OBJECTDESC objdesc;
  353. ZeroMemory(&objdesc,sizeof(DMUS_OBJECTDESC));
  354. objdesc.dwSize=sizeof(DMUS_OBJECTDESC);
  355. objdesc.dwValidData=DMUS_OBJ_MEMORY | DMUS_OBJ_CLASS ;
  356. objdesc.guidClass=CLSID_DirectMusicChordMap;
  357. objdesc.llMemLength =(LONGLONG)dwSize;
  358. objdesc.pbMemData =(BYTE*)pMem;
  359. IDirectMusicSegment8 *pOut=NULL;
  360. hr=m__dxj_DirectMusicLoader->GetObject(&objdesc,IID_IDirectMusicChordMap8,(void**)&pOut);
  361. if FAILED(hr) {
  362. //MessageBox(NULL,"GetObject Failed","test",MB_OK);
  363. return hr;
  364. }
  365. if (!pOut)return E_OUTOFMEMORY;
  366. INTERNAL_CREATE_NOADDREF(_dxj_DirectMusicChordMap,pOut,ret);
  367. if (!*ret)return E_OUTOFMEMORY;
  368. return hr;
  369. }
  370. HRESULT STDMETHODCALLTYPE C_dxj_DirectMusicLoaderObject::setSearchDirectory( BSTR dir)
  371. {
  372. HRESULT hr;
  373. hr=m__dxj_DirectMusicLoader->SetSearchDirectory(GUID_DirectMusicAllTypes,dir, TRUE); //?
  374. return hr;
  375. }