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.

1367 lines
41 KiB

  1. // Direct.cpp : Implementation of DLL Exports.
  2. // To fully complete this project follow these steps
  3. // You will need the new MIDL compiler to build this project. Additionally,
  4. // if you are building the proxy stub DLL, you will need new headers and libs.
  5. // 1) Add a custom build step to Direct.idl
  6. // You can select all of the .IDL files by holding Ctrl and clicking on
  7. // each of them.
  8. //
  9. // Description
  10. // Running MIDL
  11. // Build Command(s)
  12. // midl Direct.idl
  13. // Outputs
  14. // Direct.tlb
  15. // Direct.h
  16. // Direct_i.c
  17. //
  18. // NOTE: You must use the MIDL compiler from NT 4.0,
  19. // preferably 3.00.15 or greater
  20. //
  21. // 2) Add a custom build step to the project to register the DLL
  22. // For this, you can select all projects at once
  23. // Description
  24. // Registering OLE Server...
  25. // Build Command(s)
  26. // regsvr32 /s /c "$(TargetPath)"
  27. // echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg"
  28. // Outputs
  29. // $(OutDir)\regsvr32.trg
  30. // 3) To add UNICODE support, follow these steps
  31. // Select Build|Configurations...
  32. // Press Add...
  33. // Change the configuration name to Unicode Release
  34. // Change the "Copy Settings From" combo to Direct - Win32 Release
  35. // Press OK
  36. // Press Add...
  37. // Change the configuration name to Unicode Debug
  38. // Change the "Copy Settings From" combo to Direct - Win32 Debug
  39. // Press OK
  40. // Press "Close"
  41. // Select Build|Settings...
  42. // Select the two UNICODE projects and press the C++ tab.
  43. // Select the "General" category
  44. // Add _UNICODE to the Preprocessor definitions
  45. // Select the Unicode Debug project
  46. // Press the "General" tab
  47. // Specify DebugU for the intermediate and output directories
  48. // Select the Unicode Release project
  49. // Press the "General" tab
  50. // Specify ReleaseU for the intermediate and output directories
  51. // 4) Proxy stub DLL
  52. // To build a separate proxy/stub DLL,
  53. // run nmake -f ps.mak in the project directory.
  54. #include "stdafx.h"
  55. #include "d3d8.h"
  56. #include "resource.h"
  57. #include "initguid.h"
  58. #include "Direct.h"
  59. #include "dms.h"
  60. #include "DxGlob7Obj.h"
  61. #include "d3dx8obj.h"
  62. #include "dSoundObj.h"
  63. #include "dSoundBufferObj.h"
  64. #include "dSound3DListener.h"
  65. #include "dSound3DBuffer.h"
  66. #include "dSoundCaptureObj.h"
  67. #include "dSoundCaptureBufferObj.h"
  68. #include "DPlayPeerObj.h"
  69. #include "dPlayVoiceClientObj.h"
  70. #include "dInput1Obj.h"
  71. #include "dInputDeviceObj.h"
  72. #define IID_DEFINED
  73. #include "Direct_i.c"
  74. // When floating-point types are used, the compiler emits a reference to
  75. // _fltused to initialize the CRT's floating-point package. We're not
  76. // using any of that support and the OS is responsible for initializing
  77. // the FPU, so we'll link to the following _fltused instead to avoid CRT
  78. // bloat.
  79. //
  80. // win2k doesnt like this so its been removed
  81. // #ifdef NDEBUG
  82. // extern "C" int _fltused = 0;
  83. // #endif
  84. // ATL COM OBJECT MAP
  85. CComModule _Module;
  86. BEGIN_OBJECT_MAP(ObjectMap)
  87. OBJECT_ENTRY(CLSID__dxj_DirectX8, C_dxj_DirectX7Object)
  88. OBJECT_ENTRY(CLSID_D3DX8, C_dxj_D3DX8Object)
  89. END_OBJECT_MAP()
  90. //
  91. // thanks to precompiled headers, we never get this properly!
  92. //
  93. #undef DEFINE_GUID
  94. #define __based(a)
  95. #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
  96. EXTERN_C const GUID CDECL __based(__segname("_CODE")) name \
  97. = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
  98. // MISC GLOBALS
  99. static const char c_szWav[] = "WAVE";
  100. long g_debuglevel=0;
  101. extern "C" int nObjects = 0;
  102. BOOL is4Bit = FALSE;
  103. int g_creationcount=0;
  104. CRITICAL_SECTION g_cbCriticalSection;
  105. OSVERSIONINFOW sysinfo;
  106. // HANDLES TO DX DLLS
  107. HINSTANCE g_hDSoundHandle=NULL;
  108. HINSTANCE g_hDPlay=NULL;
  109. HINSTANCE g_hInstDINPUTDLL=NULL;
  110. HINSTANCE g_hInstD3DXOFDLL=NULL;
  111. HINSTANCE g_hInst=NULL;
  112. HINSTANCE g_hD3D8=NULL;
  113. void *g_dxj_DirectSound3dListener = 0;
  114. void *g_dxj_DirectSoundBuffer = 0;
  115. void *g_dxj_DirectSoundPrimaryBuffer = 0;
  116. void *g_dxj_DirectSound3dBuffer = 0;
  117. void *g_dxj_DirectSound = 0;
  118. void *g_dxj_DirectSoundCapture = 0;
  119. void *g_dxj_DirectSoundCaptureBuffer = 0;
  120. #if 0
  121. void *g_dxj_DirectMusic = 0;
  122. void *g_dxj_DirectSoundWave = 0;
  123. void *g_dxj_DirectSoundDownloadedWave = 0;
  124. void *g_dxj_DirectSoundSink = 0;
  125. void *g_dxj_DirectSoundSource = 0;
  126. void *g_dxj_ReferenceClock = 0;
  127. void *g_dxj_DirectMusicVoice = 0;
  128. void *g_dxj_DirectMusicPort = 0;
  129. void *g_dxj_DirectMusicBuffer = 0;
  130. #endif
  131. void *g_dxj_DirectSoundFXSend = 0;
  132. void *g_dxj_DirectSoundFXChorus = 0;
  133. void *g_dxj_DirectSoundFXFlanger = 0;
  134. void *g_dxj_DirectSoundFXEcho = 0;
  135. void *g_dxj_DirectSoundFXDistortion = 0;
  136. void *g_dxj_DirectSoundFXGargle = 0;
  137. void *g_dxj_DirectSoundFXCompressor = 0;
  138. void *g_dxj_DirectSoundFXI3DL2Source = 0;
  139. void *g_dxj_DirectSoundFXI3DL2Reverb = 0;
  140. void *g_dxj_DirectSoundFXParamEQ = 0;
  141. void *g_dxj_DirectSoundFXWavesReverb = 0;
  142. void *g_dxj_DirectInput8 = 0;
  143. void *g_dxj_DirectInputDevice8 = 0;
  144. void *g_dxj_DirectInputEffect = 0;
  145. void *g_dxj_DirectMusicLoader = 0;
  146. void *g_dxj_DirectMusicPerformance = 0;
  147. void *g_dxj_DirectMusicComposer = 0;
  148. void *g_dxj_DirectMusicStyle = 0;
  149. void *g_dxj_DirectMusicBand = 0;
  150. void *g_dxj_DirectMusicChordMap = 0;
  151. void *g_dxj_DirectMusicSegment = 0;
  152. void *g_dxj_DirectMusicSegmentState = 0;
  153. void *g_dxj_DirectMusicCollection = 0;
  154. void *g_dxj_DirectMusicAudioPath = 0;
  155. void *g_dxj_DirectMusicSong = 0;
  156. void *g_dxj_DirectPlayVoiceClient = 0;
  157. void *g_dxj_DirectPlayVoiceServer = 0;
  158. void *g_dxj_DirectPlayVoiceSetup = 0;
  159. void *g_dxj_DirectPlay = 0;
  160. void *g_dxj_DirectPlayPeer = 0;
  161. void *g_dxj_DirectPlayServer = 0;
  162. void *g_dxj_DirectPlayClient = 0;
  163. void *g_dxj_DirectPlayAddress = 0;
  164. void *g_dxj_DirectPlayLobbyClient = 0;
  165. void *g_dxj_DirectPlayLobbiedApplication= 0;
  166. /////////////////////////////////////////////////////////////////////////////
  167. /////////////////////////////////////////////////////////////////////////////
  168. /////////////////////////////////////////////////////////////////////////////
  169. //
  170. // DLL LOADING
  171. //
  172. /////////////////////////////////////////////////////////////////////////////
  173. /////////////////////////////////////////////////////////////////////////////
  174. /////////////////////////////////////////////////////////////////////////////
  175. HINSTANCE LoadD3DXOFDLL()
  176. {
  177. //char Path[MAX_PATH];
  178. //if (!g_hInstD3DXOFDLL)
  179. //{
  180. // GetSystemDirectory( Path, MAX_PATH );
  181. // strcat(Path, "\\d3dXOF.dll" );
  182. // g_hInstD3DXOFDLL=LoadLibrary(Path);
  183. //}
  184. if (!g_hInstD3DXOFDLL) g_hInstD3DXOFDLL=LoadLibrary("d3dXOF.dll");
  185. return g_hInstD3DXOFDLL;
  186. }
  187. HINSTANCE LoadD3D8DLL()
  188. {
  189. if (!g_hD3D8) g_hD3D8=LoadLibrary("d3d8.dll");
  190. return g_hD3D8;
  191. }
  192. HINSTANCE LoadDSoundDLL()
  193. {
  194. //char Path[MAX_PATH];
  195. //if (!g_hDSoundHandle)
  196. //{
  197. // GetSystemDirectory( Path, MAX_PATH );
  198. // strcat(Path, "\\dsound.dll" );
  199. // g_hDSoundHandle=LoadLibrary( Path );
  200. //}
  201. if (!g_hDSoundHandle) g_hDSoundHandle=LoadLibrary("dsound.dll");
  202. return g_hDSoundHandle;
  203. }
  204. HINSTANCE LoadDPlayDLL()
  205. {
  206. //char Path[MAX_PATH];
  207. //if (!g_hDPlay)
  208. //{
  209. // GetSystemDirectory( Path, MAX_PATH );
  210. // strcat(Path, "\\dplayx.dll" );
  211. // g_hDPlay=LoadLibrary( Path );
  212. //}
  213. if (!g_hDPlay) g_hDPlay=LoadLibrary("dplayx.dll");
  214. return g_hDPlay;
  215. }
  216. HINSTANCE LoadDINPUTDLL()
  217. {
  218. //if (!g_hInstDINPUTDLL) {
  219. // char Path[MAX_PATH];
  220. // GetSystemDirectory( Path, MAX_PATH );
  221. // strcat(Path, "\\dinput8.dll" );
  222. // g_hInstDINPUTDLL=LoadLibrary( Path );
  223. //}
  224. if (!g_hInstDINPUTDLL) g_hInstDINPUTDLL=LoadLibrary("dinput8.dll");
  225. return g_hInstDINPUTDLL;
  226. }
  227. /////////////////////////////////////////////////////////////////////////////
  228. /////////////////////////////////////////////////////////////////////////////
  229. /////////////////////////////////////////////////////////////////////////////
  230. //
  231. // DLL ENTRY POINTS
  232. //
  233. /////////////////////////////////////////////////////////////////////////////
  234. /////////////////////////////////////////////////////////////////////////////
  235. /////////////////////////////////////////////////////////////////////////////
  236. /////////////////////////////////////////////////////////////////////////////
  237. // DLL Entry Point
  238. extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  239. {
  240. g_hInst=hInstance;
  241. if (dwReason == DLL_PROCESS_ATTACH)
  242. {
  243. //
  244. // Get the current display pixel depth
  245. // If it is 4-bit we are in trouble.
  246. //
  247. HDC hDisplayIC;
  248. BOOL bPalette = FALSE;
  249. hDisplayIC = CreateIC("DISPLAY", NULL, NULL, NULL);
  250. if (hDisplayIC)
  251. {
  252. if (GetDeviceCaps(hDisplayIC, BITSPIXEL) < 8)
  253. is4Bit = TRUE;
  254. DeleteDC(hDisplayIC);
  255. }
  256. _Module.Init(ObjectMap, hInstance);
  257. DisableThreadLibraryCalls(hInstance);
  258. InitializeCriticalSection(&g_cbCriticalSection);
  259. HKEY hk=0;
  260. DWORD type=REG_DWORD;
  261. LONG res;
  262. DWORD cbSize = sizeof(DWORD);
  263. res=RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Directx\\DXVB",&hk);
  264. if (hk)
  265. {
  266. res=RegQueryValueEx(hk,"DebugLevel",NULL,&type,(LPBYTE)&g_debuglevel,&cbSize);
  267. }
  268. RegCloseKey(hk);
  269. nObjects = 0;
  270. }
  271. else if (dwReason == DLL_PROCESS_DETACH)
  272. {
  273. DeleteCriticalSection(&g_cbCriticalSection);
  274. //FREE DLLS
  275. if ( g_hDPlay )
  276. FreeLibrary(g_hDPlay);
  277. if ( g_hDSoundHandle )
  278. FreeLibrary(g_hDSoundHandle);
  279. if ( g_hInstDINPUTDLL )
  280. FreeLibrary(g_hInstDINPUTDLL);
  281. if (g_hInstD3DXOFDLL)
  282. FreeLibrary(g_hInstD3DXOFDLL);
  283. if (g_hD3D8)
  284. FreeLibrary(g_hD3D8);
  285. _Module.Term();
  286. }
  287. return TRUE;
  288. }
  289. /////////////////////////////////////////////////////////////////////////////
  290. // Used to determine whether the DLL can be unloaded by OLE
  291. STDAPI DllCanUnloadNow(void)
  292. {
  293. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  294. }
  295. /////////////////////////////////////////////////////////////////////////////
  296. // Returns a class factory to create an object of the requested type
  297. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  298. {
  299. return _Module.GetClassObject(rclsid, riid, ppv);
  300. }
  301. /////////////////////////////////////////////////////////////////////////////
  302. // DllRegisterServer - Adds entries to the system registry
  303. STDAPI DllRegisterServer(void)
  304. {
  305. HRESULT hRes = S_OK;
  306. // registers object, typelib and all interfaces in typelib
  307. hRes = _Module.RegisterServer(TRUE);
  308. if(hRes == S_OK)
  309. {
  310. //hRes = RegSecurityClass();
  311. }
  312. //now look
  313. HKEY hk=0;
  314. char szDocPath[MAX_PATH];
  315. DWORD cb=MAX_PATH;
  316. LONG res;
  317. DWORD type=REG_SZ;
  318. ZeroMemory(szDocPath,MAX_PATH);
  319. res=RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Directx SDK",&hk);
  320. if ((ERROR_SUCCESS!=res)||(hk==0) )
  321. return hRes;
  322. res=RegQueryValueEx(hk,"DX81SDK Doc Path",NULL,&type,(LPBYTE)szDocPath,&cb);
  323. RegCloseKey(hk);
  324. if (ERROR_SUCCESS!=res) return hRes;
  325. hk=0;
  326. res=RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\CLASSES\\TypeLib\\{E1211242-8E94-11d1-8808-00C04FC2C603}\\1.0\\HELPDIR",&hk);
  327. if (ERROR_SUCCESS!=res) return hRes;
  328. RegSetValueEx(hk,NULL,0,REG_SZ,(LPBYTE)szDocPath,cb);
  329. RegCloseKey(hk);
  330. return hRes;
  331. }
  332. /////////////////////////////////////////////////////////////////////////////
  333. // DllUnregisterServer - Adds entries to the system registry
  334. STDAPI DllUnregisterServer(void)
  335. {
  336. HRESULT hRes = S_OK;
  337. hRes = _Module.UnregisterServer();
  338. if(hRes == S_OK)
  339. {
  340. //hRes = UnRegSecurityClass();
  341. }
  342. return hRes;
  343. }
  344. /////////////////////////////////////////////////////////////////////////////
  345. /////////////////////////////////////////////////////////////////////////////
  346. /////////////////////////////////////////////////////////////////////////////
  347. //
  348. // GUID CONVERSION FUNCTIONS
  349. //
  350. /////////////////////////////////////////////////////////////////////////////
  351. /////////////////////////////////////////////////////////////////////////////
  352. /////////////////////////////////////////////////////////////////////////////
  353. /////////////////////////////////////////////////////////////////////////////
  354. // GUIDS_EQUAL - consider moving to dms.h
  355. #define GUIDS_EQUAL(g,g2) (\
  356. (g.Data1==g2->Data1) && \
  357. (g.Data2==g2->Data2) && \
  358. (g.Data3==g2->Data3) && \
  359. (g.Data4[0]==g2->Data4[0]) && \
  360. (g.Data4[1]==g2->Data4[1]) && \
  361. (g.Data4[2]==g2->Data4[2]) && \
  362. (g.Data4[3]==g2->Data4[3]) && \
  363. (g.Data4[4]==g2->Data4[4]) && \
  364. (g.Data4[5]==g2->Data4[5]) && \
  365. (g.Data4[6]==g2->Data4[6]) && \
  366. (g.Data4[7]==g2->Data4[7]) )
  367. /////////////////////////////////////////////////////////////////////////////
  368. // GUIDtoBSTR - does conversion
  369. BSTR GUIDtoBSTR(LPGUID pGuid){
  370. char szOut[256];
  371. char szTemp[10];
  372. char *pAt=NULL;
  373. int i;
  374. BSTR bstrOut;
  375. // 00000000001111111111222222222233333333
  376. // 01234567890123456789012345678901234567
  377. // {XXXXXXXX-XXXX-XXXX-X XXX-XXXXXXXXXXXX}
  378. if (pGuid!=NULL){
  379. szOut[0]='{';
  380. wsprintf(&(szOut)[1],"%.8X",pGuid->Data1);
  381. szOut[9]='-';
  382. wsprintf(szTemp,"%.4X",pGuid->Data2);
  383. memcpy(&(szOut[10]),szTemp,4);
  384. szOut[14]='-';
  385. wsprintf(szTemp,"%.4X",pGuid->Data3);
  386. memcpy(&(szOut[15]),szTemp,4);
  387. szOut[19]='-';
  388. for (i=0;i<2;i++){
  389. wsprintf(szTemp,"%.2X",pGuid->Data4[i]);
  390. memcpy(&(szOut[20+i*2]),szTemp,2);
  391. }
  392. szOut[24]='-';
  393. for (i=2;i<8;i++){
  394. wsprintf(szTemp,"%.2X",pGuid->Data4[i]);
  395. memcpy(&(szOut[21+i*2]),szTemp,2);
  396. }
  397. szOut[37]='}';
  398. szOut[38]='\0';
  399. USES_CONVERSION;
  400. bstrOut = T2BSTR(szOut);
  401. }
  402. else {
  403. bstrOut = T2BSTR("");
  404. }
  405. return bstrOut;
  406. }
  407. //////////////////////////////////////////////////////////////////////////////
  408. // convertChar
  409. // helper for GUIDtoBSTR
  410. HRESULT convertChar(char *szIn,int i,char *valOut){
  411. int val[2]; //using int for easy out of bounds check
  412. char c;
  413. int j;
  414. for (j=0;j<2;j++){
  415. c= szIn[i+j];
  416. switch (c)
  417. {
  418. case 'a':
  419. case 'A':
  420. val[j]=10;
  421. break;
  422. case 'b':
  423. case 'B':
  424. val[j]=11;
  425. break;
  426. case 'c':
  427. case 'C':
  428. val[j]=12;
  429. break;
  430. case 'd':
  431. case 'D':
  432. val[j]=13;
  433. break;
  434. case 'e':
  435. case 'E':
  436. val[j]=14;
  437. break;
  438. case 'f':
  439. case 'F':
  440. val[j]=15;
  441. break;
  442. default:
  443. val[j]=c-'0';
  444. if (val[j]<0) return E_INVALIDARG;
  445. if (val[j]>15) return E_INVALIDARG;
  446. break;
  447. }
  448. }
  449. *valOut=(char)((val[0]<<4)|val[1]);
  450. return S_OK;
  451. }
  452. /////////////////////////////////////////////////////////////////////////////
  453. // BSTRtoGUID - does conversion
  454. //
  455. HRESULT BSTRtoGUID(LPGUID pGuid, BSTR bstr){
  456. HRESULT hr;
  457. //byte
  458. //
  459. //
  460. //char
  461. // 1111111111222222222233333333
  462. // 01234567890123456789012345678901234567
  463. // {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
  464. USES_CONVERSION;
  465. if(!pGuid) return E_INVALIDARG;
  466. ZeroMemory(pGuid,sizeof(GUID));
  467. if (!bstr) return S_OK;
  468. if (bstr[0]==0x00) return S_OK;
  469. LPSTR szGuid = NULL;
  470. __try { szGuid=W2T(bstr); } __except(EXCEPTION_EXECUTE_HANDLER) { return E_FAIL; }
  471. //first and last char should be { }
  472. if ((szGuid[0]!='{')||(szGuid[37]!='}'))
  473. return E_INVALIDARG;
  474. if ((szGuid[9]!='-')||(szGuid[14]!='-')||(szGuid[19]!='-')||(szGuid[24]!='-'))
  475. return E_INVALIDARG;
  476. char val;
  477. char *pData=(char*)pGuid;
  478. int j=0;
  479. int i;
  480. //FIRST DWORD
  481. for ( i=7;i>=1;i=i-2){
  482. hr=convertChar(szGuid,i,&val);
  483. if FAILED(hr) return hr;
  484. pData[j++]=val;
  485. }
  486. //FIRST WORD
  487. for ( i=12;i>=10;i=i-2){
  488. hr=convertChar(szGuid,i,&val);
  489. if FAILED(hr) return hr;
  490. pData[j++]=val;
  491. }
  492. //2nd WORD
  493. for ( i=17;i>=15;i=i-2){
  494. hr=convertChar(szGuid,i,&val);
  495. if FAILED(hr) return hr;
  496. pData[j++]=val;
  497. }
  498. //3rd DWORD - BYTE ARRAY
  499. for ( i=20;i<24;i=i+2){
  500. hr=convertChar(szGuid,i,&val);
  501. if FAILED(hr) return hr;
  502. pData[j++]=val;
  503. }
  504. //BYTE ARRAY
  505. for ( i=25;i<37;i=i+2){
  506. hr=convertChar(szGuid,i,&val);
  507. if FAILED(hr) return hr;
  508. pData[j++]=val;
  509. }
  510. return S_OK;
  511. }
  512. /////////////////////////////////////////////////////////////////////////////
  513. //
  514. //
  515. HRESULT BSTRtoPPGUID(LPGUID *ppGuid, BSTR bstr){
  516. if (!ppGuid) return E_INVALIDARG;
  517. if ((bstr==NULL)||(bstr[0]=='\0')){
  518. *ppGuid=NULL;
  519. return S_OK;
  520. }
  521. return BSTRtoGUID(*ppGuid,bstr);
  522. }
  523. /////////////////////////////////////////////////////////////////////////////
  524. // D3DBSTRtoGUID - does conversion
  525. //
  526. HRESULT D3DBSTRtoGUID(LPGUID pGuid,BSTR str){
  527. HRESULT hr=S_OK;
  528. if (!pGuid) return E_INVALIDARG;
  529. if (!str) {
  530. ZeroMemory(pGuid,sizeof(GUID));
  531. return S_OK;
  532. }
  533. //if( 0==_wcsicmp(str,L"iid_idirect3drgbdevice")){
  534. // memcpy(pGuid,&IID_IDirect3DRGBDevice,sizeof(GUID));
  535. //}
  536. //else if( 0==_wcsicmp(str,L"iid_idirect3dhaldevice")){
  537. // memcpy(pGuid,&IID_IDirect3DHALDevice,sizeof(GUID));
  538. //}
  539. //else if( 0==_wcsicmp(str,L"iid_idirect3dmmxdevice")){
  540. // memcpy(pGuid,&IID_IDirect3DMMXDevice,sizeof(GUID));
  541. //}
  542. //else if( 0==_wcsicmp(str,L"iid_idirect3drefdevice")){
  543. // memcpy(pGuid,&IID_IDirect3DRefDevice,sizeof(GUID));
  544. //}
  545. //else if( 0==_wcsicmp(str,L"iid_idirect3dnulldevice")){
  546. // memcpy(pGuid,&IID_IDirect3DNullDevice,sizeof(GUID));
  547. //}
  548. //else {
  549. // hr = BSTRtoGUID(pGuid,str);
  550. //}
  551. return hr;
  552. }
  553. /////////////////////////////////////////////////////////////////////////////
  554. // D3DGUIDtoBSTR - does conversion
  555. //
  556. BSTR D3DGUIDtoBSTR(LPGUID pg){
  557. HRESULT hr=S_OK;
  558. WCHAR *pStr=NULL;
  559. if (!pg)
  560. return NULL;
  561. //else if (GUIDS_EQUAL(IID_IDirect3DNullDevice,pg)){
  562. // pStr=L"IID_IDirect3DNullDevice";
  563. //}
  564. //else if (GUIDS_EQUAL(IID_IDirect3DRefDevice,pg)){
  565. // pStr=L"IID_IDirect3DRefDevice";
  566. //}
  567. //else if (GUIDS_EQUAL(IID_IDirect3DMMXDevice,pg)){
  568. // pStr=L"IID_IDirect3DMMXDevice";
  569. //}
  570. //
  571. //else if (GUIDS_EQUAL(IID_IDirect3DHALDevice,pg)){
  572. // pStr=L"IID_IDirect3DHALDevice";
  573. //}
  574. //else if (GUIDS_EQUAL(IID_IDirect3DRGBDevice,pg)){
  575. // pStr=L"IID_IDirect3DRGBDevice";
  576. //}
  577. //
  578. if (pStr){
  579. return DXALLOCBSTR(pStr);
  580. }
  581. else {
  582. return GUIDtoBSTR(pg);
  583. }
  584. }
  585. /////////////////////////////////////////////////////////////////////////////
  586. // DSOUNDEFFECTSBSTRtoGUID - does conversion
  587. //
  588. HRESULT AudioBSTRtoGUID(LPGUID pGuid,BSTR str){
  589. HRESULT hr=S_OK;
  590. if (!pGuid) return E_INVALIDARG;
  591. if (!str) {
  592. ZeroMemory(pGuid,sizeof(GUID));
  593. return S_OK;
  594. }
  595. #if 0
  596. if( 0==_wcsicmp(str,L"guid_dsfx_send")){
  597. memcpy(pGuid,&GUID_DSFX_SEND,sizeof(GUID));
  598. }
  599. else if( 0==_wcsicmp(str,L"iid_directsoundfxsend")){
  600. memcpy(pGuid,&IID_IDirectSoundFXSend,sizeof(GUID));
  601. }
  602. #endif
  603. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_chorus")){
  604. memcpy(pGuid,&GUID_DSFX_STANDARD_CHORUS,sizeof(GUID));
  605. }
  606. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_flanger")){
  607. memcpy(pGuid,&GUID_DSFX_STANDARD_FLANGER,sizeof(GUID));
  608. }
  609. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_echo")){
  610. memcpy(pGuid,&GUID_DSFX_STANDARD_ECHO,sizeof(GUID));
  611. }
  612. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_distortion")){
  613. memcpy(pGuid,&GUID_DSFX_STANDARD_DISTORTION,sizeof(GUID));
  614. }
  615. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_compressor")){
  616. memcpy(pGuid,&GUID_DSFX_STANDARD_COMPRESSOR,sizeof(GUID));
  617. }
  618. #if 0
  619. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_i3dl2source")){
  620. memcpy(pGuid,&GUID_DSFX_STANDARD_I3DL2SOURCE,sizeof(GUID));
  621. }
  622. #endif
  623. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_i3dl2reverb")){
  624. memcpy(pGuid,&GUID_DSFX_STANDARD_I3DL2REVERB,sizeof(GUID));
  625. }
  626. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_gargle")){
  627. memcpy(pGuid,&GUID_DSFX_STANDARD_GARGLE,sizeof(GUID));
  628. }
  629. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_parameq")){
  630. memcpy(pGuid,&GUID_DSFX_STANDARD_PARAMEQ,sizeof(GUID));
  631. }
  632. else if( 0==_wcsicmp(str,L"guid_dsfx_waves_reverb")){
  633. memcpy(pGuid,&GUID_DSFX_WAVES_REVERB,sizeof(GUID));
  634. }
  635. else if( 0==_wcsicmp(str,L"iid_directsoundfxgargle")){
  636. memcpy(pGuid,&IID_IDirectSoundFXGargle,sizeof(GUID));
  637. }
  638. else if( 0==_wcsicmp(str,L"iid_directsoundfxchorus")){
  639. memcpy(pGuid,&IID_IDirectSoundFXChorus,sizeof(GUID));
  640. }
  641. else if( 0==_wcsicmp(str,L"iid_directsoundfxcompressor")){
  642. memcpy(pGuid,&IID_IDirectSoundFXCompressor,sizeof(GUID));
  643. }
  644. else if( 0==_wcsicmp(str,L"iid_directsoundfxdistortion")){
  645. memcpy(pGuid,&IID_IDirectSoundFXDistortion,sizeof(GUID));
  646. }
  647. else if( 0==_wcsicmp(str,L"iid_directsoundfxecho")){
  648. memcpy(pGuid,&IID_IDirectSoundFXEcho,sizeof(GUID));
  649. }
  650. else if( 0==_wcsicmp(str,L"iid_directsoundfxflanger")){
  651. memcpy(pGuid,&IID_IDirectSoundFXFlanger,sizeof(GUID));
  652. }
  653. else if( 0==_wcsicmp(str,L"iid_directsoundfxi3dl2reverb")){
  654. memcpy(pGuid,&IID_IDirectSoundFXI3DL2Reverb,sizeof(GUID));
  655. }
  656. #if 0
  657. else if( 0==_wcsicmp(str,L"iid_directsoundfxi3dl2source")){
  658. memcpy(pGuid,&IID_IDirectSoundFXI3DL2Source,sizeof(GUID));
  659. }
  660. #endif
  661. else if( 0==_wcsicmp(str,L"iid_directsoundfxparameq")){
  662. memcpy(pGuid,&IID_IDirectSoundFXParamEq,sizeof(GUID));
  663. }
  664. else if( 0==_wcsicmp(str,L"iid_directsoundfxwavesreverb")){
  665. memcpy(pGuid,&IID_IDirectSoundFXWavesReverb,sizeof(GUID));
  666. }
  667. else if( 0==_wcsicmp(str,L"ds3dalg_default")){
  668. memcpy(pGuid,&DS3DALG_DEFAULT,sizeof(GUID));
  669. }
  670. else if( 0==_wcsicmp(str,L"ds3dalg_no_virtualization")){
  671. memcpy(pGuid,&DS3DALG_NO_VIRTUALIZATION,sizeof(GUID));
  672. }
  673. else if( 0==_wcsicmp(str,L"ds3dalg_hrtf_full")){
  674. memcpy(pGuid,&DS3DALG_HRTF_FULL,sizeof(GUID));
  675. }
  676. else if( 0==_wcsicmp(str,L"ds3dalg_hrtf_light")){
  677. memcpy(pGuid,&DS3DALG_HRTF_LIGHT,sizeof(GUID));
  678. }
  679. else if( 0==_wcsicmp(str,L"dsdevid_defaultplayback")){
  680. memcpy(pGuid,&DSDEVID_DefaultPlayback,sizeof(GUID));
  681. }
  682. else if( 0==_wcsicmp(str,L"dsdevid_defaultcapture")){
  683. memcpy(pGuid,&DSDEVID_DefaultCapture,sizeof(GUID));
  684. }
  685. else if( 0==_wcsicmp(str,L"dsdevid_defaultvoiceplayback")){
  686. memcpy(pGuid,&DSDEVID_DefaultVoicePlayback,sizeof(GUID));
  687. }
  688. else if( 0==_wcsicmp(str,L"dsdevid_defaultvoicecapture")){
  689. memcpy(pGuid,&DSDEVID_DefaultVoiceCapture,sizeof(GUID));
  690. }
  691. else if( 0==_wcsicmp(str,L"iid_idirectsoundbuffer8")){
  692. memcpy(pGuid,&IID_IDirectSoundBuffer8,sizeof(GUID));
  693. }
  694. else if( 0==_wcsicmp(str,L"iid_idirectsoundbuffer")){
  695. memcpy(pGuid,&IID_IDirectSoundBuffer,sizeof(GUID));
  696. }
  697. else if( 0==_wcsicmp(str,L"iid_idirectsound3dlistener")){
  698. memcpy(pGuid,&IID_IDirectSound3DListener,sizeof(GUID));
  699. }
  700. else if( 0==_wcsicmp(str,L"guid_all_objects")){
  701. memcpy(pGuid,&GUID_All_Objects,sizeof(GUID));
  702. }
  703. else if( 0==_wcsicmp(str,L"iid_idirectsound3dbuffer")){
  704. memcpy(pGuid,&IID_IDirectSound3DBuffer,sizeof(GUID));
  705. }
  706. else {
  707. hr = BSTRtoGUID(pGuid,str);
  708. }
  709. return hr;
  710. }
  711. /////////////////////////////////////////////////////////////////////////////
  712. // DPLAYBSTRtoGUID - does conversion
  713. //
  714. HRESULT DPLAYBSTRtoGUID(LPGUID pGuid,BSTR str){
  715. HRESULT hr=S_OK;
  716. if (!pGuid) return E_INVALIDARG;
  717. if (!str) {
  718. ZeroMemory(pGuid,sizeof(GUID));
  719. return S_OK;
  720. }
  721. if( 0==_wcsicmp(str,L"clsid_dp8sp_tcpip")){
  722. memcpy(pGuid,&CLSID_DP8SP_TCPIP,sizeof(GUID));
  723. }
  724. else if( 0==_wcsicmp(str,L"clsid_dp8sp_ipx")){
  725. memcpy(pGuid,&CLSID_DP8SP_IPX,sizeof(GUID));
  726. }
  727. else if( 0==_wcsicmp(str,L"clsid_dp8sp_modem")){
  728. memcpy(pGuid,&CLSID_DP8SP_MODEM,sizeof(GUID));
  729. }
  730. else if( 0==_wcsicmp(str,L"clsid_dp8sp_serial")){
  731. memcpy(pGuid,&CLSID_DP8SP_SERIAL,sizeof(GUID));
  732. }
  733. else if( 0==_wcsicmp(str,L"dsdevid_defaultplayback")){
  734. memcpy(pGuid,&DSDEVID_DefaultPlayback,sizeof(GUID));
  735. }
  736. else if( 0==_wcsicmp(str,L"dsdevid_defaultcapture")){
  737. memcpy(pGuid,&DSDEVID_DefaultCapture,sizeof(GUID));
  738. }
  739. else if( 0==_wcsicmp(str,L"dsdevid_defaultvoiceplayback")){
  740. memcpy(pGuid,&DSDEVID_DefaultVoicePlayback,sizeof(GUID));
  741. }
  742. else if( 0==_wcsicmp(str,L"dsdevid_defaultvoicecapture")){
  743. memcpy(pGuid,&DSDEVID_DefaultVoiceCapture,sizeof(GUID));
  744. }
  745. else {
  746. hr = BSTRtoGUID(pGuid,str);
  747. }
  748. return hr;
  749. }
  750. /////////////////////////////////////////////////////////////////////////////
  751. // DINPUTGUIDtoBSTR
  752. //
  753. BSTR DINPUTGUIDtoBSTR(LPGUID pg){
  754. HRESULT hr=S_OK;
  755. WCHAR *pStr=NULL;
  756. if (!pg)
  757. return NULL;
  758. else if (GUIDS_EQUAL(GUID_XAxis,pg)){
  759. pStr=L"GUID_XAxis";
  760. }
  761. else if (GUIDS_EQUAL(GUID_YAxis,pg)){
  762. pStr=L"GUID_YAxis";
  763. }
  764. else if (GUIDS_EQUAL(GUID_ZAxis,pg)){
  765. pStr=L"GUID_ZAxis";
  766. }
  767. else if (GUIDS_EQUAL(GUID_RxAxis,pg)){
  768. pStr=L"GUID_RxAxis";
  769. }
  770. else if (GUIDS_EQUAL(GUID_RyAxis,pg)){
  771. pStr=L"GUID_RyAxis";
  772. }
  773. else if (GUIDS_EQUAL(GUID_RzAxis,pg)){
  774. pStr=L"GUID_RzAxis";
  775. }
  776. else if (GUIDS_EQUAL(GUID_Slider,pg)){
  777. pStr=L"GUID_Slider";
  778. }
  779. else if (GUIDS_EQUAL(GUID_Button,pg)){
  780. pStr=L"GUID_Button";
  781. }
  782. else if (GUIDS_EQUAL(GUID_Key,pg)){
  783. pStr=L"GUID_Key";
  784. }
  785. else if (GUIDS_EQUAL(GUID_POV,pg)){
  786. pStr=L"GUID_POV";
  787. }
  788. else if (GUIDS_EQUAL(GUID_Unknown,pg)){
  789. pStr=L"GUID_Unknown";
  790. }
  791. else if (GUIDS_EQUAL(GUID_SysMouse,pg)){
  792. pStr=L"GUID_SysMouse";
  793. }
  794. else if (GUIDS_EQUAL(GUID_SysKeyboard,pg)){
  795. pStr=L"GUID_SysKeyboard";
  796. }
  797. else if (GUIDS_EQUAL(GUID_ConstantForce,pg)){
  798. pStr=L"GUID_ConstantForce";
  799. }
  800. else if (GUIDS_EQUAL(GUID_Square,pg)){
  801. pStr=L"GUID_Square";
  802. }
  803. else if (GUIDS_EQUAL(GUID_Sine,pg)){
  804. pStr=L"GUID_Sine";
  805. }
  806. else if (GUIDS_EQUAL(GUID_Triangle,pg)){
  807. pStr=L"GUID_Triangle";
  808. }
  809. else if (GUIDS_EQUAL(GUID_SawtoothUp,pg)){
  810. pStr=L"GUID_SawtoothUp";
  811. }
  812. else if (GUIDS_EQUAL(GUID_SawtoothDown,pg)){
  813. pStr=L"GUID_SawtoothDown";
  814. }
  815. else if (GUIDS_EQUAL(GUID_Spring,pg)){
  816. pStr=L"GUID_Spring";
  817. }
  818. else if (GUIDS_EQUAL(GUID_Damper,pg)){
  819. pStr=L"GUID_Damper";
  820. }
  821. else if (GUIDS_EQUAL(GUID_Inertia,pg)){
  822. pStr=L"GUID_Inertia";
  823. }
  824. else if (GUIDS_EQUAL(GUID_Friction,pg)){
  825. pStr=L"GUID_Friction";
  826. }
  827. else if (GUIDS_EQUAL(GUID_CustomForce,pg)){
  828. pStr=L"GUID_CustomForce";
  829. }
  830. else if (GUIDS_EQUAL(GUID_RampForce,pg)){
  831. pStr=L"GUID_RampForce";
  832. }
  833. //else if (GUIDS_EQUAL(GUID_Joystick,pg)){
  834. // pStr=L"GUID_JoyStick";
  835. //}
  836. if (pStr){
  837. return DXALLOCBSTR(pStr);
  838. }
  839. else {
  840. return GUIDtoBSTR(pg);
  841. }
  842. }
  843. /////////////////////////////////////////////////////////////////////////////
  844. // DINPUTBSTRtoGUID
  845. //
  846. HRESULT DINPUTBSTRtoGUID(LPGUID pGuid,BSTR str){
  847. HRESULT hr=S_OK;
  848. if (!pGuid) return E_INVALIDARG;
  849. if (!str) {
  850. ZeroMemory(pGuid,sizeof(GUID));
  851. return S_OK;
  852. }
  853. if( 0==_wcsicmp(str,L"guid_xaxis")){
  854. memcpy(pGuid,&GUID_XAxis,sizeof(GUID));
  855. }
  856. else if( 0==_wcsicmp(str,L"guid_yaxis")){
  857. memcpy(pGuid,&GUID_YAxis,sizeof(GUID));
  858. }
  859. else if( 0==_wcsicmp(str,L"guid_zaxis")){
  860. memcpy(pGuid,&GUID_ZAxis,sizeof(GUID));
  861. }
  862. else if( 0==_wcsicmp(str,L"guid_rxaxis")){
  863. memcpy(pGuid,&GUID_RxAxis,sizeof(GUID));
  864. }
  865. else if( 0==_wcsicmp(str,L"guid_ryaxis")){
  866. memcpy(pGuid,&GUID_RyAxis,sizeof(GUID));
  867. }
  868. else if( 0==_wcsicmp(str,L"guid_rzaxis")){
  869. memcpy(pGuid,&GUID_RzAxis,sizeof(GUID));
  870. }
  871. else if( 0==_wcsicmp(str,L"guid_slider")){
  872. memcpy(pGuid,&GUID_Slider,sizeof(GUID));
  873. }
  874. else if( 0==_wcsicmp(str,L"guid_button")){
  875. memcpy(pGuid,&GUID_Button,sizeof(GUID));
  876. }
  877. else if( 0==_wcsicmp(str,L"guid_key")){
  878. memcpy(pGuid,&GUID_Key,sizeof(GUID));
  879. }
  880. else if( 0==_wcsicmp(str,L"guid_pov")){
  881. memcpy(pGuid,&GUID_POV,sizeof(GUID));
  882. }
  883. else if( 0==_wcsicmp(str,L"guid_unknown")){
  884. memcpy(pGuid,&GUID_Unknown,sizeof(GUID));
  885. }
  886. else if( 0==_wcsicmp(str,L"guid_sysmouse")){
  887. memcpy(pGuid,&GUID_SysMouse,sizeof(GUID));
  888. }
  889. else if( 0==_wcsicmp(str,L"guid_syskeyboard")){
  890. memcpy(pGuid,&GUID_SysKeyboard,sizeof(GUID));
  891. }
  892. else if( 0==_wcsicmp(str,L"guid_constantforce")){
  893. memcpy(pGuid,&GUID_ConstantForce,sizeof(GUID));
  894. }
  895. else if( 0==_wcsicmp(str,L"guid_square")){
  896. memcpy(pGuid,&GUID_Square,sizeof(GUID));
  897. }
  898. else if( 0==_wcsicmp(str,L"guid_sine")){
  899. memcpy(pGuid,&GUID_Sine,sizeof(GUID));
  900. }
  901. else if( 0==_wcsicmp(str,L"guid_triangle")){
  902. memcpy(pGuid,&GUID_Triangle,sizeof(GUID));
  903. }
  904. else if( 0==_wcsicmp(str,L"guid_sawtoothup")){
  905. memcpy(pGuid,&GUID_SawtoothUp,sizeof(GUID));
  906. }
  907. else if( 0==_wcsicmp(str,L"guid_sawtoothdown")){
  908. memcpy(pGuid,&GUID_SawtoothDown,sizeof(GUID));
  909. }
  910. else if( 0==_wcsicmp(str,L"guid_spring")){
  911. memcpy(pGuid,&GUID_Spring,sizeof(GUID));
  912. }
  913. else if( 0==_wcsicmp(str,L"guid_damper")){
  914. memcpy(pGuid,&GUID_Damper,sizeof(GUID));
  915. }
  916. else if( 0==_wcsicmp(str,L"guid_inertia")){
  917. memcpy(pGuid,&GUID_Inertia,sizeof(GUID));
  918. }
  919. else if( 0==_wcsicmp(str,L"guid_friction")){
  920. memcpy(pGuid,&GUID_Friction,sizeof(GUID));
  921. }
  922. else if( 0==_wcsicmp(str,L"guid_customforce")){
  923. memcpy(pGuid,&GUID_CustomForce,sizeof(GUID));
  924. }
  925. else if( 0==_wcsicmp(str,L"guid_rampforce")){
  926. memcpy(pGuid,&GUID_RampForce,sizeof(GUID));
  927. }
  928. //else if( 0==_wcsicmp(str,L"guid_joystick")){
  929. // memcpy(pGuid,&GUID_Joystick,sizeof(GUID));
  930. //}
  931. else {
  932. hr = BSTRtoGUID(pGuid,str);
  933. }
  934. return hr;
  935. }
  936. /////////////////////////////////////////////////////////////////////////////
  937. /////////////////////////////////////////////////////////////////////////////
  938. /////////////////////////////////////////////////////////////////////////////
  939. //
  940. // GENERAL HELPER FUNCTIONS
  941. //
  942. /////////////////////////////////////////////////////////////////////////////
  943. /////////////////////////////////////////////////////////////////////////////
  944. /////////////////////////////////////////////////////////////////////////////
  945. /////////////////////////////////////////////////////////////////////////////
  946. // Given an ANSI string, pass back a UNICODE string
  947. // SysAllocString is your big friend here.
  948. //
  949. // CONSIDER finding all occerence of use and replacint with the
  950. // T2BSTR macro .. much cleaner
  951. //
  952. extern "C" void PassBackUnicode(LPSTR str, BSTR *Name, DWORD cnt)
  953. {
  954. //docdoc: length header is required to be filled, but the BSTR pointer
  955. // points to the first character, not the length.
  956. // note, the count can never be too small as we get that from the string
  957. // before we pass it in!
  958. USES_CONVERSION;
  959. LPWSTR lpw = (LPWSTR)malloc((cnt+1)*2);
  960. if (!lpw)
  961. return;
  962. void *l = (void *)lpw;
  963. lpw = AtlA2WHelper(lpw, str, cnt);
  964. lpw[cnt] = 0;
  965. *Name = SysAllocString(lpw);
  966. free(l);
  967. }
  968. /////////////////////////////////////////////////////////////////////////////
  969. // IsAllZeros
  970. //
  971. BOOL IsEmptyString(BSTR szString)
  972. {
  973. __try {
  974. if (*szString)
  975. return FALSE;
  976. else
  977. return TRUE;
  978. }
  979. __except(EXCEPTION_EXECUTE_HANDLER)
  980. {
  981. return TRUE;
  982. }
  983. }
  984. /////////////////////////////////////////////////////////////////////////////
  985. // IsAllZeros
  986. //
  987. BOOL IsAllZeros(void *pStruct,DWORD size){
  988. for (DWORD i=0;i<size;i++){
  989. if (((char*)pStruct)[i]!='\0'){
  990. return FALSE;
  991. }
  992. }
  993. return TRUE;
  994. }
  995. /////////////////////////////////////////////////////////////////////////////
  996. // CopyFloats
  997. //
  998. extern "C" void CopyFloats(D3DVALUE *dst, D3DVALUE *src, DWORD count)
  999. {
  1000. D3DVALUE *ptr1 = dst, *ptr2 = src;
  1001. if (!count) return;
  1002. for (; count; count--) *ptr1++ = *ptr2++;
  1003. return;
  1004. }
  1005. /////////////////////////////////////////////////////////////////////////////
  1006. // IsWin95
  1007. //
  1008. // no longer needed since we support w95 now
  1009. #if 0
  1010. BOOL IsWin95(void)
  1011. {
  1012. return FALSE;
  1013. //We work on win95
  1014. OSVERSIONINFO osvi;
  1015. ZeroMemory(&osvi, sizeof(osvi));
  1016. osvi.dwOSVersionInfoSize = sizeof(osvi);
  1017. if (!GetVersionEx(&osvi))
  1018. {
  1019. DPF(1,"GetVersionEx failed - assuming Win95");
  1020. return TRUE;
  1021. }
  1022. if ( VER_PLATFORM_WIN32_WINDOWS == osvi.dwPlatformId )
  1023. {
  1024. if( ( osvi.dwMajorVersion > 4UL ) ||
  1025. ( ( osvi.dwMajorVersion == 4UL ) &&
  1026. ( osvi.dwMinorVersion >= 10UL ) &&
  1027. ( LOWORD( osvi.dwBuildNumber ) >= 1373 ) ) )
  1028. {
  1029. // is Win98
  1030. DPF(2,"Detected Win98");
  1031. return FALSE;
  1032. }
  1033. else
  1034. {
  1035. // is Win95
  1036. DPF(2,"Detected Win95");
  1037. return TRUE;
  1038. }
  1039. }
  1040. else if ( VER_PLATFORM_WIN32_NT == osvi.dwPlatformId )
  1041. {
  1042. DPF(2,"Detected WinNT");
  1043. return FALSE;
  1044. }
  1045. DPF(2,"OS Detection failed");
  1046. return TRUE;
  1047. }
  1048. #endif
  1049. #define DICONDITION_USE_BOTH_AXIS 1
  1050. #define DICONDITION_USE_DIRECTION 2
  1051. /////////////////////////////////////////////////////////////////////////////
  1052. // FixUpRealEffect cover->real
  1053. //
  1054. HRESULT FixUpRealEffect(GUID g,DIEFFECT *realEffect,DIEFFECT_CDESC *cover)
  1055. {
  1056. if (!cover) return E_INVALIDARG;
  1057. memcpy(realEffect,cover,sizeof(DIEFFECT));
  1058. realEffect->dwSize =sizeof(DIEFFECT);
  1059. realEffect->lpEnvelope =NULL;
  1060. realEffect->cbTypeSpecificParams =0;
  1061. realEffect->lpvTypeSpecificParams =NULL;
  1062. realEffect->cAxes =2;
  1063. realEffect->dwFlags=realEffect->dwFlags | DIEFF_OBJECTOFFSETS ;
  1064. realEffect->rglDirection =(long*)&(cover->x);
  1065. realEffect->rgdwAxes =(DWORD*)&(cover->axisOffsets);
  1066. if (cover->bUseEnvelope){
  1067. realEffect->lpEnvelope=(DIENVELOPE*)&(cover->envelope);
  1068. ((DIENVELOPE*)&(cover->envelope))->dwSize=sizeof(DIENVELOPE);
  1069. }
  1070. if (!cover->lFlags)
  1071. realEffect->dwFlags= DIEFF_POLAR | DIEFF_OBJECTOFFSETS ;
  1072. //constant
  1073. if (g==GUID_ConstantForce)
  1074. {
  1075. realEffect->cbTypeSpecificParams =sizeof (DICONSTANTFORCE);
  1076. realEffect->lpvTypeSpecificParams =&(cover->constantForce);
  1077. }
  1078. //periodic
  1079. else if ((g==GUID_Square)||(g==GUID_Triangle)||(g==GUID_SawtoothUp)||(g==GUID_SawtoothDown)||(g==GUID_Sine))
  1080. {
  1081. realEffect->cbTypeSpecificParams =sizeof (DIPERIODIC);
  1082. realEffect->lpvTypeSpecificParams =&(cover->periodicForce);
  1083. }
  1084. else if ((g==GUID_Spring)|| (g==GUID_Damper)|| (g==GUID_Inertia)|| (g==GUID_Friction)){
  1085. if (cover->conditionFlags==DICONDITION_USE_BOTH_AXIS){
  1086. realEffect->cbTypeSpecificParams =sizeof(DICONDITION)*2;
  1087. realEffect->lpvTypeSpecificParams =&(cover->conditionX);
  1088. }
  1089. else{
  1090. realEffect->cbTypeSpecificParams =sizeof(DICONDITION);
  1091. realEffect->lpvTypeSpecificParams =&(cover->conditionX);
  1092. }
  1093. }
  1094. else if (g==GUID_RampForce){
  1095. realEffect->cbTypeSpecificParams =sizeof(DIRAMPFORCE);
  1096. realEffect->lpvTypeSpecificParams =&(cover->rampForce);
  1097. }
  1098. cover->axisOffsets.x=DIJOFS_X;
  1099. cover->axisOffsets.y=DIJOFS_Y;
  1100. realEffect->rgdwAxes=(DWORD*)&(cover->axisOffsets);
  1101. return S_OK;
  1102. }
  1103. /////////////////////////////////////////////////////////////////////////////
  1104. // FixUpCoverEffect real->cover
  1105. //
  1106. HRESULT FixUpCoverEffect(GUID g, DIEFFECT_CDESC *cover,DIEFFECT *realEffect)
  1107. {
  1108. ZeroMemory(cover,sizeof(DIEFFECT_CDESC));
  1109. memcpy(cover,realEffect,sizeof(DIEFFECT));
  1110. if (realEffect->lpEnvelope){
  1111. memcpy(&cover->envelope,realEffect->lpEnvelope ,sizeof(DIENVELOPE));
  1112. cover->bUseEnvelope=VARIANT_TRUE;
  1113. }
  1114. if (realEffect->rglDirection){
  1115. cover->x=realEffect->rglDirection[0];
  1116. cover->y=realEffect->rglDirection[1];
  1117. }
  1118. if (realEffect->lpvTypeSpecificParams){
  1119. if (g==GUID_ConstantForce)
  1120. {
  1121. memcpy(&(cover->constantForce),realEffect->lpvTypeSpecificParams,sizeof(DICONSTANTFORCE));
  1122. }
  1123. //periodic
  1124. else if ((g==GUID_Square)||(g==GUID_Triangle)||(g==GUID_SawtoothUp)||(g==GUID_SawtoothDown)||(g==GUID_Sine))
  1125. {
  1126. memcpy(&(cover->periodicForce),realEffect->lpvTypeSpecificParams,sizeof(DIPERIODIC));
  1127. }
  1128. else if ((g==GUID_Spring)|| (g==GUID_Damper)|| (g==GUID_Inertia)|| (g==GUID_Friction)){
  1129. if (realEffect->cbTypeSpecificParams ==sizeof(DICONDITION)*2){
  1130. memcpy(&(cover->conditionY),realEffect->lpvTypeSpecificParams,sizeof(DICONDITION)*2);
  1131. cover->conditionFlags=DICONDITION_USE_BOTH_AXIS;
  1132. }
  1133. else{
  1134. memcpy(&(cover->conditionX),realEffect->lpvTypeSpecificParams,sizeof(DICONDITION));
  1135. cover->conditionFlags=DICONDITION_USE_DIRECTION;
  1136. }
  1137. }
  1138. else if (g==GUID_RampForce){
  1139. memcpy(&(cover->rampForce),realEffect->lpvTypeSpecificParams,sizeof(DIRAMPFORCE));
  1140. }
  1141. }
  1142. return S_OK;
  1143. }
  1144. #define MYVARIANTINIT(inArg,puser) \
  1145. VariantInit(puser); \
  1146. user.vt=VT_UNKNOWN; \
  1147. user.punkVal = inArg; \
  1148. user.punkVal->AddRef();