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.

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