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.

1366 lines
39 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",&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=W2T(bstr);
  470. //first and last char should be { }
  471. if ((szGuid[0]!='{')||(szGuid[37]!='}'))
  472. return E_INVALIDARG;
  473. if ((szGuid[9]!='-')||(szGuid[14]!='-')||(szGuid[19]!='-')||(szGuid[24]!='-'))
  474. return E_INVALIDARG;
  475. char val;
  476. char *pData=(char*)pGuid;
  477. int j=0;
  478. int i;
  479. //FIRST DWORD
  480. for ( i=7;i>=1;i=i-2){
  481. hr=convertChar(szGuid,i,&val);
  482. if FAILED(hr) return hr;
  483. pData[j++]=val;
  484. }
  485. //FIRST WORD
  486. for ( i=12;i>=10;i=i-2){
  487. hr=convertChar(szGuid,i,&val);
  488. if FAILED(hr) return hr;
  489. pData[j++]=val;
  490. }
  491. //2nd WORD
  492. for ( i=17;i>=15;i=i-2){
  493. hr=convertChar(szGuid,i,&val);
  494. if FAILED(hr) return hr;
  495. pData[j++]=val;
  496. }
  497. //3rd DWORD - BYTE ARRAY
  498. for ( i=20;i<24;i=i+2){
  499. hr=convertChar(szGuid,i,&val);
  500. if FAILED(hr) return hr;
  501. pData[j++]=val;
  502. }
  503. //BYTE ARRAY
  504. for ( i=25;i<37;i=i+2){
  505. hr=convertChar(szGuid,i,&val);
  506. if FAILED(hr) return hr;
  507. pData[j++]=val;
  508. }
  509. return S_OK;
  510. }
  511. /////////////////////////////////////////////////////////////////////////////
  512. //
  513. //
  514. HRESULT BSTRtoPPGUID(LPGUID *ppGuid, BSTR bstr){
  515. if (!ppGuid) return E_INVALIDARG;
  516. if ((bstr==NULL)||(bstr[0]=='\0')){
  517. *ppGuid=NULL;
  518. return S_OK;
  519. }
  520. return BSTRtoGUID(*ppGuid,bstr);
  521. }
  522. /////////////////////////////////////////////////////////////////////////////
  523. // D3DBSTRtoGUID - does conversion
  524. //
  525. HRESULT D3DBSTRtoGUID(LPGUID pGuid,BSTR str){
  526. HRESULT hr=S_OK;
  527. if (!pGuid) return E_INVALIDARG;
  528. if (!str) {
  529. ZeroMemory(pGuid,sizeof(GUID));
  530. return S_OK;
  531. }
  532. //if( 0==_wcsicmp(str,L"iid_idirect3drgbdevice")){
  533. // memcpy(pGuid,&IID_IDirect3DRGBDevice,sizeof(GUID));
  534. //}
  535. //else if( 0==_wcsicmp(str,L"iid_idirect3dhaldevice")){
  536. // memcpy(pGuid,&IID_IDirect3DHALDevice,sizeof(GUID));
  537. //}
  538. //else if( 0==_wcsicmp(str,L"iid_idirect3dmmxdevice")){
  539. // memcpy(pGuid,&IID_IDirect3DMMXDevice,sizeof(GUID));
  540. //}
  541. //else if( 0==_wcsicmp(str,L"iid_idirect3drefdevice")){
  542. // memcpy(pGuid,&IID_IDirect3DRefDevice,sizeof(GUID));
  543. //}
  544. //else if( 0==_wcsicmp(str,L"iid_idirect3dnulldevice")){
  545. // memcpy(pGuid,&IID_IDirect3DNullDevice,sizeof(GUID));
  546. //}
  547. //else {
  548. // hr = BSTRtoGUID(pGuid,str);
  549. //}
  550. return hr;
  551. }
  552. /////////////////////////////////////////////////////////////////////////////
  553. // D3DGUIDtoBSTR - does conversion
  554. //
  555. BSTR D3DGUIDtoBSTR(LPGUID pg){
  556. HRESULT hr=S_OK;
  557. WCHAR *pStr=NULL;
  558. if (!pg)
  559. return NULL;
  560. //else if (GUIDS_EQUAL(IID_IDirect3DNullDevice,pg)){
  561. // pStr=L"IID_IDirect3DNullDevice";
  562. //}
  563. //else if (GUIDS_EQUAL(IID_IDirect3DRefDevice,pg)){
  564. // pStr=L"IID_IDirect3DRefDevice";
  565. //}
  566. //else if (GUIDS_EQUAL(IID_IDirect3DMMXDevice,pg)){
  567. // pStr=L"IID_IDirect3DMMXDevice";
  568. //}
  569. //
  570. //else if (GUIDS_EQUAL(IID_IDirect3DHALDevice,pg)){
  571. // pStr=L"IID_IDirect3DHALDevice";
  572. //}
  573. //else if (GUIDS_EQUAL(IID_IDirect3DRGBDevice,pg)){
  574. // pStr=L"IID_IDirect3DRGBDevice";
  575. //}
  576. //
  577. if (pStr){
  578. return DXALLOCBSTR(pStr);
  579. }
  580. else {
  581. return GUIDtoBSTR(pg);
  582. }
  583. }
  584. /////////////////////////////////////////////////////////////////////////////
  585. // DSOUNDEFFECTSBSTRtoGUID - does conversion
  586. //
  587. HRESULT AudioBSTRtoGUID(LPGUID pGuid,BSTR str){
  588. HRESULT hr=S_OK;
  589. if (!pGuid) return E_INVALIDARG;
  590. if (!str) {
  591. ZeroMemory(pGuid,sizeof(GUID));
  592. return S_OK;
  593. }
  594. #if 0
  595. if( 0==_wcsicmp(str,L"guid_dsfx_send")){
  596. memcpy(pGuid,&GUID_DSFX_SEND,sizeof(GUID));
  597. }
  598. else if( 0==_wcsicmp(str,L"iid_directsoundfxsend")){
  599. memcpy(pGuid,&IID_IDirectSoundFXSend,sizeof(GUID));
  600. }
  601. #endif
  602. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_chorus")){
  603. memcpy(pGuid,&GUID_DSFX_STANDARD_CHORUS,sizeof(GUID));
  604. }
  605. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_flanger")){
  606. memcpy(pGuid,&GUID_DSFX_STANDARD_FLANGER,sizeof(GUID));
  607. }
  608. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_echo")){
  609. memcpy(pGuid,&GUID_DSFX_STANDARD_ECHO,sizeof(GUID));
  610. }
  611. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_distortion")){
  612. memcpy(pGuid,&GUID_DSFX_STANDARD_DISTORTION,sizeof(GUID));
  613. }
  614. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_compressor")){
  615. memcpy(pGuid,&GUID_DSFX_STANDARD_COMPRESSOR,sizeof(GUID));
  616. }
  617. #if 0
  618. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_i3dl2source")){
  619. memcpy(pGuid,&GUID_DSFX_STANDARD_I3DL2SOURCE,sizeof(GUID));
  620. }
  621. #endif
  622. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_i3dl2reverb")){
  623. memcpy(pGuid,&GUID_DSFX_STANDARD_I3DL2REVERB,sizeof(GUID));
  624. }
  625. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_gargle")){
  626. memcpy(pGuid,&GUID_DSFX_STANDARD_GARGLE,sizeof(GUID));
  627. }
  628. else if( 0==_wcsicmp(str,L"guid_dsfx_standard_parameq")){
  629. memcpy(pGuid,&GUID_DSFX_STANDARD_PARAMEQ,sizeof(GUID));
  630. }
  631. else if( 0==_wcsicmp(str,L"guid_dsfx_waves_reverb")){
  632. memcpy(pGuid,&GUID_DSFX_WAVES_REVERB,sizeof(GUID));
  633. }
  634. else if( 0==_wcsicmp(str,L"iid_directsoundfxgargle")){
  635. memcpy(pGuid,&IID_IDirectSoundFXGargle,sizeof(GUID));
  636. }
  637. else if( 0==_wcsicmp(str,L"iid_directsoundfxchorus")){
  638. memcpy(pGuid,&IID_IDirectSoundFXChorus,sizeof(GUID));
  639. }
  640. else if( 0==_wcsicmp(str,L"iid_directsoundfxcompressor")){
  641. memcpy(pGuid,&IID_IDirectSoundFXCompressor,sizeof(GUID));
  642. }
  643. else if( 0==_wcsicmp(str,L"iid_directsoundfxdistortion")){
  644. memcpy(pGuid,&IID_IDirectSoundFXDistortion,sizeof(GUID));
  645. }
  646. else if( 0==_wcsicmp(str,L"iid_directsoundfxecho")){
  647. memcpy(pGuid,&IID_IDirectSoundFXEcho,sizeof(GUID));
  648. }
  649. else if( 0==_wcsicmp(str,L"iid_directsoundfxflanger")){
  650. memcpy(pGuid,&IID_IDirectSoundFXFlanger,sizeof(GUID));
  651. }
  652. else if( 0==_wcsicmp(str,L"iid_directsoundfxi3dl2reverb")){
  653. memcpy(pGuid,&IID_IDirectSoundFXI3DL2Reverb,sizeof(GUID));
  654. }
  655. #if 0
  656. else if( 0==_wcsicmp(str,L"iid_directsoundfxi3dl2source")){
  657. memcpy(pGuid,&IID_IDirectSoundFXI3DL2Source,sizeof(GUID));
  658. }
  659. #endif
  660. else if( 0==_wcsicmp(str,L"iid_directsoundfxparameq")){
  661. memcpy(pGuid,&IID_IDirectSoundFXParamEq,sizeof(GUID));
  662. }
  663. else if( 0==_wcsicmp(str,L"iid_directsoundfxwavesreverb")){
  664. memcpy(pGuid,&IID_IDirectSoundFXWavesReverb,sizeof(GUID));
  665. }
  666. else if( 0==_wcsicmp(str,L"ds3dalg_default")){
  667. memcpy(pGuid,&DS3DALG_DEFAULT,sizeof(GUID));
  668. }
  669. else if( 0==_wcsicmp(str,L"ds3dalg_no_virtualization")){
  670. memcpy(pGuid,&DS3DALG_NO_VIRTUALIZATION,sizeof(GUID));
  671. }
  672. else if( 0==_wcsicmp(str,L"ds3dalg_hrtf_full")){
  673. memcpy(pGuid,&DS3DALG_HRTF_FULL,sizeof(GUID));
  674. }
  675. else if( 0==_wcsicmp(str,L"ds3dalg_hrtf_light")){
  676. memcpy(pGuid,&DS3DALG_HRTF_LIGHT,sizeof(GUID));
  677. }
  678. else if( 0==_wcsicmp(str,L"dsdevid_defaultplayback")){
  679. memcpy(pGuid,&DSDEVID_DefaultPlayback,sizeof(GUID));
  680. }
  681. else if( 0==_wcsicmp(str,L"dsdevid_defaultcapture")){
  682. memcpy(pGuid,&DSDEVID_DefaultCapture,sizeof(GUID));
  683. }
  684. else if( 0==_wcsicmp(str,L"dsdevid_defaultvoiceplayback")){
  685. memcpy(pGuid,&DSDEVID_DefaultVoicePlayback,sizeof(GUID));
  686. }
  687. else if( 0==_wcsicmp(str,L"dsdevid_defaultvoicecapture")){
  688. memcpy(pGuid,&DSDEVID_DefaultVoiceCapture,sizeof(GUID));
  689. }
  690. else if( 0==_wcsicmp(str,L"iid_idirectsoundbuffer8")){
  691. memcpy(pGuid,&IID_IDirectSoundBuffer8,sizeof(GUID));
  692. }
  693. else if( 0==_wcsicmp(str,L"iid_idirectsoundbuffer")){
  694. memcpy(pGuid,&IID_IDirectSoundBuffer,sizeof(GUID));
  695. }
  696. else if( 0==_wcsicmp(str,L"iid_idirectsound3dlistener")){
  697. memcpy(pGuid,&IID_IDirectSound3DListener,sizeof(GUID));
  698. }
  699. else if( 0==_wcsicmp(str,L"guid_all_objects")){
  700. memcpy(pGuid,&GUID_All_Objects,sizeof(GUID));
  701. }
  702. else if( 0==_wcsicmp(str,L"iid_idirectsound3dbuffer")){
  703. memcpy(pGuid,&IID_IDirectSound3DBuffer,sizeof(GUID));
  704. }
  705. else {
  706. hr = BSTRtoGUID(pGuid,str);
  707. }
  708. return hr;
  709. }
  710. /////////////////////////////////////////////////////////////////////////////
  711. // DPLAYBSTRtoGUID - does conversion
  712. //
  713. HRESULT DPLAYBSTRtoGUID(LPGUID pGuid,BSTR str){
  714. HRESULT hr=S_OK;
  715. if (!pGuid) return E_INVALIDARG;
  716. if (!str) {
  717. ZeroMemory(pGuid,sizeof(GUID));
  718. return S_OK;
  719. }
  720. if( 0==_wcsicmp(str,L"clsid_dp8sp_tcpip")){
  721. memcpy(pGuid,&CLSID_DP8SP_TCPIP,sizeof(GUID));
  722. }
  723. else if( 0==_wcsicmp(str,L"clsid_dp8sp_ipx")){
  724. memcpy(pGuid,&CLSID_DP8SP_IPX,sizeof(GUID));
  725. }
  726. else if( 0==_wcsicmp(str,L"clsid_dp8sp_modem")){
  727. memcpy(pGuid,&CLSID_DP8SP_MODEM,sizeof(GUID));
  728. }
  729. else if( 0==_wcsicmp(str,L"clsid_dp8sp_serial")){
  730. memcpy(pGuid,&CLSID_DP8SP_SERIAL,sizeof(GUID));
  731. }
  732. else if( 0==_wcsicmp(str,L"dsdevid_defaultplayback")){
  733. memcpy(pGuid,&DSDEVID_DefaultPlayback,sizeof(GUID));
  734. }
  735. else if( 0==_wcsicmp(str,L"dsdevid_defaultcapture")){
  736. memcpy(pGuid,&DSDEVID_DefaultCapture,sizeof(GUID));
  737. }
  738. else if( 0==_wcsicmp(str,L"dsdevid_defaultvoiceplayback")){
  739. memcpy(pGuid,&DSDEVID_DefaultVoicePlayback,sizeof(GUID));
  740. }
  741. else if( 0==_wcsicmp(str,L"dsdevid_defaultvoicecapture")){
  742. memcpy(pGuid,&DSDEVID_DefaultVoiceCapture,sizeof(GUID));
  743. }
  744. else {
  745. hr = BSTRtoGUID(pGuid,str);
  746. }
  747. return hr;
  748. }
  749. /////////////////////////////////////////////////////////////////////////////
  750. // DINPUTGUIDtoBSTR
  751. //
  752. BSTR DINPUTGUIDtoBSTR(LPGUID pg){
  753. HRESULT hr=S_OK;
  754. WCHAR *pStr=NULL;
  755. if (!pg)
  756. return NULL;
  757. else if (GUIDS_EQUAL(GUID_XAxis,pg)){
  758. pStr=L"GUID_XAxis";
  759. }
  760. else if (GUIDS_EQUAL(GUID_YAxis,pg)){
  761. pStr=L"GUID_YAxis";
  762. }
  763. else if (GUIDS_EQUAL(GUID_ZAxis,pg)){
  764. pStr=L"GUID_ZAxis";
  765. }
  766. else if (GUIDS_EQUAL(GUID_RxAxis,pg)){
  767. pStr=L"GUID_RxAxis";
  768. }
  769. else if (GUIDS_EQUAL(GUID_RyAxis,pg)){
  770. pStr=L"GUID_RyAxis";
  771. }
  772. else if (GUIDS_EQUAL(GUID_RzAxis,pg)){
  773. pStr=L"GUID_RzAxis";
  774. }
  775. else if (GUIDS_EQUAL(GUID_Slider,pg)){
  776. pStr=L"GUID_Slider";
  777. }
  778. else if (GUIDS_EQUAL(GUID_Button,pg)){
  779. pStr=L"GUID_Button";
  780. }
  781. else if (GUIDS_EQUAL(GUID_Key,pg)){
  782. pStr=L"GUID_Key";
  783. }
  784. else if (GUIDS_EQUAL(GUID_POV,pg)){
  785. pStr=L"GUID_POV";
  786. }
  787. else if (GUIDS_EQUAL(GUID_Unknown,pg)){
  788. pStr=L"GUID_Unknown";
  789. }
  790. else if (GUIDS_EQUAL(GUID_SysMouse,pg)){
  791. pStr=L"GUID_SysMouse";
  792. }
  793. else if (GUIDS_EQUAL(GUID_SysKeyboard,pg)){
  794. pStr=L"GUID_SysKeyboard";
  795. }
  796. else if (GUIDS_EQUAL(GUID_ConstantForce,pg)){
  797. pStr=L"GUID_ConstantForce";
  798. }
  799. else if (GUIDS_EQUAL(GUID_Square,pg)){
  800. pStr=L"GUID_Square";
  801. }
  802. else if (GUIDS_EQUAL(GUID_Sine,pg)){
  803. pStr=L"GUID_Sine";
  804. }
  805. else if (GUIDS_EQUAL(GUID_Triangle,pg)){
  806. pStr=L"GUID_Triangle";
  807. }
  808. else if (GUIDS_EQUAL(GUID_SawtoothUp,pg)){
  809. pStr=L"GUID_SawtoothUp";
  810. }
  811. else if (GUIDS_EQUAL(GUID_SawtoothDown,pg)){
  812. pStr=L"GUID_SawtoothDown";
  813. }
  814. else if (GUIDS_EQUAL(GUID_Spring,pg)){
  815. pStr=L"GUID_Spring";
  816. }
  817. else if (GUIDS_EQUAL(GUID_Damper,pg)){
  818. pStr=L"GUID_Damper";
  819. }
  820. else if (GUIDS_EQUAL(GUID_Inertia,pg)){
  821. pStr=L"GUID_Inertia";
  822. }
  823. else if (GUIDS_EQUAL(GUID_Friction,pg)){
  824. pStr=L"GUID_Friction";
  825. }
  826. else if (GUIDS_EQUAL(GUID_CustomForce,pg)){
  827. pStr=L"GUID_CustomForce";
  828. }
  829. else if (GUIDS_EQUAL(GUID_RampForce,pg)){
  830. pStr=L"GUID_RampForce";
  831. }
  832. //else if (GUIDS_EQUAL(GUID_Joystick,pg)){
  833. // pStr=L"GUID_JoyStick";
  834. //}
  835. if (pStr){
  836. return DXALLOCBSTR(pStr);
  837. }
  838. else {
  839. return GUIDtoBSTR(pg);
  840. }
  841. }
  842. /////////////////////////////////////////////////////////////////////////////
  843. // DINPUTBSTRtoGUID
  844. //
  845. HRESULT DINPUTBSTRtoGUID(LPGUID pGuid,BSTR str){
  846. HRESULT hr=S_OK;
  847. if (!pGuid) return E_INVALIDARG;
  848. if (!str) {
  849. ZeroMemory(pGuid,sizeof(GUID));
  850. return S_OK;
  851. }
  852. if( 0==_wcsicmp(str,L"guid_xaxis")){
  853. memcpy(pGuid,&GUID_XAxis,sizeof(GUID));
  854. }
  855. else if( 0==_wcsicmp(str,L"guid_yaxis")){
  856. memcpy(pGuid,&GUID_YAxis,sizeof(GUID));
  857. }
  858. else if( 0==_wcsicmp(str,L"guid_zaxis")){
  859. memcpy(pGuid,&GUID_ZAxis,sizeof(GUID));
  860. }
  861. else if( 0==_wcsicmp(str,L"guid_rxaxis")){
  862. memcpy(pGuid,&GUID_RxAxis,sizeof(GUID));
  863. }
  864. else if( 0==_wcsicmp(str,L"guid_ryaxis")){
  865. memcpy(pGuid,&GUID_RyAxis,sizeof(GUID));
  866. }
  867. else if( 0==_wcsicmp(str,L"guid_rzaxis")){
  868. memcpy(pGuid,&GUID_RzAxis,sizeof(GUID));
  869. }
  870. else if( 0==_wcsicmp(str,L"guid_slider")){
  871. memcpy(pGuid,&GUID_Slider,sizeof(GUID));
  872. }
  873. else if( 0==_wcsicmp(str,L"guid_button")){
  874. memcpy(pGuid,&GUID_Button,sizeof(GUID));
  875. }
  876. else if( 0==_wcsicmp(str,L"guid_key")){
  877. memcpy(pGuid,&GUID_Key,sizeof(GUID));
  878. }
  879. else if( 0==_wcsicmp(str,L"guid_pov")){
  880. memcpy(pGuid,&GUID_POV,sizeof(GUID));
  881. }
  882. else if( 0==_wcsicmp(str,L"guid_unknown")){
  883. memcpy(pGuid,&GUID_Unknown,sizeof(GUID));
  884. }
  885. else if( 0==_wcsicmp(str,L"guid_sysmouse")){
  886. memcpy(pGuid,&GUID_SysMouse,sizeof(GUID));
  887. }
  888. else if( 0==_wcsicmp(str,L"guid_syskeyboard")){
  889. memcpy(pGuid,&GUID_SysKeyboard,sizeof(GUID));
  890. }
  891. else if( 0==_wcsicmp(str,L"guid_constantforce")){
  892. memcpy(pGuid,&GUID_ConstantForce,sizeof(GUID));
  893. }
  894. else if( 0==_wcsicmp(str,L"guid_square")){
  895. memcpy(pGuid,&GUID_Square,sizeof(GUID));
  896. }
  897. else if( 0==_wcsicmp(str,L"guid_sine")){
  898. memcpy(pGuid,&GUID_Sine,sizeof(GUID));
  899. }
  900. else if( 0==_wcsicmp(str,L"guid_triangle")){
  901. memcpy(pGuid,&GUID_Triangle,sizeof(GUID));
  902. }
  903. else if( 0==_wcsicmp(str,L"guid_sawtoothup")){
  904. memcpy(pGuid,&GUID_SawtoothUp,sizeof(GUID));
  905. }
  906. else if( 0==_wcsicmp(str,L"guid_sawtoothdown")){
  907. memcpy(pGuid,&GUID_SawtoothDown,sizeof(GUID));
  908. }
  909. else if( 0==_wcsicmp(str,L"guid_spring")){
  910. memcpy(pGuid,&GUID_Spring,sizeof(GUID));
  911. }
  912. else if( 0==_wcsicmp(str,L"guid_damper")){
  913. memcpy(pGuid,&GUID_Damper,sizeof(GUID));
  914. }
  915. else if( 0==_wcsicmp(str,L"guid_inertia")){
  916. memcpy(pGuid,&GUID_Inertia,sizeof(GUID));
  917. }
  918. else if( 0==_wcsicmp(str,L"guid_friction")){
  919. memcpy(pGuid,&GUID_Friction,sizeof(GUID));
  920. }
  921. else if( 0==_wcsicmp(str,L"guid_customforce")){
  922. memcpy(pGuid,&GUID_CustomForce,sizeof(GUID));
  923. }
  924. else if( 0==_wcsicmp(str,L"guid_rampforce")){
  925. memcpy(pGuid,&GUID_RampForce,sizeof(GUID));
  926. }
  927. //else if( 0==_wcsicmp(str,L"guid_joystick")){
  928. // memcpy(pGuid,&GUID_Joystick,sizeof(GUID));
  929. //}
  930. else {
  931. hr = BSTRtoGUID(pGuid,str);
  932. }
  933. return hr;
  934. }
  935. /////////////////////////////////////////////////////////////////////////////
  936. /////////////////////////////////////////////////////////////////////////////
  937. /////////////////////////////////////////////////////////////////////////////
  938. //
  939. // GENERAL HELPER FUNCTIONS
  940. //
  941. /////////////////////////////////////////////////////////////////////////////
  942. /////////////////////////////////////////////////////////////////////////////
  943. /////////////////////////////////////////////////////////////////////////////
  944. /////////////////////////////////////////////////////////////////////////////
  945. // Given an ANSI string, pass back a UNICODE string
  946. // SysAllocString is your big friend here.
  947. //
  948. // CONSIDER finding all occerence of use and replacint with the
  949. // T2BSTR macro .. much cleaner
  950. //
  951. extern "C" void PassBackUnicode(LPSTR str, BSTR *Name, DWORD cnt)
  952. {
  953. //docdoc: length header is required to be filled, but the BSTR pointer
  954. // points to the first character, not the length.
  955. // note, the count can never be too small as we get that from the string
  956. // before we pass it in!
  957. USES_CONVERSION;
  958. LPWSTR lpw = (LPWSTR)malloc((cnt+1)*2);
  959. if (!lpw)
  960. return;
  961. void *l = (void *)lpw;
  962. lpw = AtlA2WHelper(lpw, str, cnt);
  963. lpw[cnt] = 0;
  964. *Name = SysAllocString(lpw);
  965. free(l);
  966. }
  967. /////////////////////////////////////////////////////////////////////////////
  968. // IsAllZeros
  969. //
  970. BOOL IsEmptyString(BSTR szString)
  971. {
  972. __try {
  973. if (*szString)
  974. return FALSE;
  975. else
  976. return TRUE;
  977. }
  978. __except(EXCEPTION_EXECUTE_HANDLER)
  979. {
  980. return TRUE;
  981. }
  982. }
  983. /////////////////////////////////////////////////////////////////////////////
  984. // IsAllZeros
  985. //
  986. BOOL IsAllZeros(void *pStruct,DWORD size){
  987. for (DWORD i=0;i<size;i++){
  988. if (((char*)pStruct)[i]!='\0'){
  989. return FALSE;
  990. }
  991. }
  992. return TRUE;
  993. }
  994. /////////////////////////////////////////////////////////////////////////////
  995. // CopyFloats
  996. //
  997. extern "C" void CopyFloats(D3DVALUE *dst, D3DVALUE *src, DWORD count)
  998. {
  999. D3DVALUE *ptr1 = dst, *ptr2 = src;
  1000. if (!count) return;
  1001. for (; count; count--) *ptr1++ = *ptr2++;
  1002. return;
  1003. }
  1004. /////////////////////////////////////////////////////////////////////////////
  1005. // IsWin95
  1006. //
  1007. // no longer needed since we support w95 now
  1008. #if 0
  1009. BOOL IsWin95(void)
  1010. {
  1011. return FALSE;
  1012. //We work on win95
  1013. OSVERSIONINFO osvi;
  1014. ZeroMemory(&osvi, sizeof(osvi));
  1015. osvi.dwOSVersionInfoSize = sizeof(osvi);
  1016. if (!GetVersionEx(&osvi))
  1017. {
  1018. DPF(1,"GetVersionEx failed - assuming Win95");
  1019. return TRUE;
  1020. }
  1021. if ( VER_PLATFORM_WIN32_WINDOWS == osvi.dwPlatformId )
  1022. {
  1023. if( ( osvi.dwMajorVersion > 4UL ) ||
  1024. ( ( osvi.dwMajorVersion == 4UL ) &&
  1025. ( osvi.dwMinorVersion >= 10UL ) &&
  1026. ( LOWORD( osvi.dwBuildNumber ) >= 1373 ) ) )
  1027. {
  1028. // is Win98
  1029. DPF(2,"Detected Win98");
  1030. return FALSE;
  1031. }
  1032. else
  1033. {
  1034. // is Win95
  1035. DPF(2,"Detected Win95");
  1036. return TRUE;
  1037. }
  1038. }
  1039. else if ( VER_PLATFORM_WIN32_NT == osvi.dwPlatformId )
  1040. {
  1041. DPF(2,"Detected WinNT");
  1042. return FALSE;
  1043. }
  1044. DPF(2,"OS Detection failed");
  1045. return TRUE;
  1046. }
  1047. #endif
  1048. #define DICONDITION_USE_BOTH_AXIS 1
  1049. #define DICONDITION_USE_DIRECTION 2
  1050. /////////////////////////////////////////////////////////////////////////////
  1051. // FixUpRealEffect cover->real
  1052. //
  1053. HRESULT FixUpRealEffect(GUID g,DIEFFECT *realEffect,DIEFFECT_CDESC *cover)
  1054. {
  1055. if (!cover) return E_INVALIDARG;
  1056. memcpy(realEffect,cover,sizeof(DIEFFECT));
  1057. realEffect->dwSize =sizeof(DIEFFECT);
  1058. realEffect->lpEnvelope =NULL;
  1059. realEffect->cbTypeSpecificParams =0;
  1060. realEffect->lpvTypeSpecificParams =NULL;
  1061. realEffect->cAxes =2;
  1062. realEffect->dwFlags=realEffect->dwFlags | DIEFF_OBJECTOFFSETS ;
  1063. realEffect->rglDirection =(long*)&(cover->x);
  1064. realEffect->rgdwAxes =(DWORD*)&(cover->axisOffsets);
  1065. if (cover->bUseEnvelope){
  1066. realEffect->lpEnvelope=(DIENVELOPE*)&(cover->envelope);
  1067. ((DIENVELOPE*)&(cover->envelope))->dwSize=sizeof(DIENVELOPE);
  1068. }
  1069. if (!cover->lFlags)
  1070. realEffect->dwFlags= DIEFF_POLAR | DIEFF_OBJECTOFFSETS ;
  1071. //constant
  1072. if (g==GUID_ConstantForce)
  1073. {
  1074. realEffect->cbTypeSpecificParams =sizeof (DICONSTANTFORCE);
  1075. realEffect->lpvTypeSpecificParams =&(cover->constantForce);
  1076. }
  1077. //periodic
  1078. else if ((g==GUID_Square)||(g==GUID_Triangle)||(g==GUID_SawtoothUp)||(g==GUID_SawtoothDown)||(g==GUID_Sine))
  1079. {
  1080. realEffect->cbTypeSpecificParams =sizeof (DIPERIODIC);
  1081. realEffect->lpvTypeSpecificParams =&(cover->periodicForce);
  1082. }
  1083. else if ((g==GUID_Spring)|| (g==GUID_Damper)|| (g==GUID_Inertia)|| (g==GUID_Friction)){
  1084. if (cover->conditionFlags==DICONDITION_USE_BOTH_AXIS){
  1085. realEffect->cbTypeSpecificParams =sizeof(DICONDITION)*2;
  1086. realEffect->lpvTypeSpecificParams =&(cover->conditionX);
  1087. }
  1088. else{
  1089. realEffect->cbTypeSpecificParams =sizeof(DICONDITION);
  1090. realEffect->lpvTypeSpecificParams =&(cover->conditionX);
  1091. }
  1092. }
  1093. else if (g==GUID_RampForce){
  1094. realEffect->cbTypeSpecificParams =sizeof(DIRAMPFORCE);
  1095. realEffect->lpvTypeSpecificParams =&(cover->rampForce);
  1096. }
  1097. cover->axisOffsets.x=DIJOFS_X;
  1098. cover->axisOffsets.y=DIJOFS_Y;
  1099. realEffect->rgdwAxes=(DWORD*)&(cover->axisOffsets);
  1100. return S_OK;
  1101. }
  1102. /////////////////////////////////////////////////////////////////////////////
  1103. // FixUpCoverEffect real->cover
  1104. //
  1105. HRESULT FixUpCoverEffect(GUID g, DIEFFECT_CDESC *cover,DIEFFECT *realEffect)
  1106. {
  1107. ZeroMemory(cover,sizeof(DIEFFECT_CDESC));
  1108. memcpy(cover,realEffect,sizeof(DIEFFECT));
  1109. if (realEffect->lpEnvelope){
  1110. memcpy(&cover->envelope,realEffect->lpEnvelope ,sizeof(DIENVELOPE));
  1111. cover->bUseEnvelope=VARIANT_TRUE;
  1112. }
  1113. if (realEffect->rglDirection){
  1114. cover->x=realEffect->rglDirection[0];
  1115. cover->y=realEffect->rglDirection[1];
  1116. }
  1117. if (realEffect->lpvTypeSpecificParams){
  1118. if (g==GUID_ConstantForce)
  1119. {
  1120. memcpy(&(cover->constantForce),realEffect->lpvTypeSpecificParams,sizeof(DICONSTANTFORCE));
  1121. }
  1122. //periodic
  1123. else if ((g==GUID_Square)||(g==GUID_Triangle)||(g==GUID_SawtoothUp)||(g==GUID_SawtoothDown)||(g==GUID_Sine))
  1124. {
  1125. memcpy(&(cover->periodicForce),realEffect->lpvTypeSpecificParams,sizeof(DIPERIODIC));
  1126. }
  1127. else if ((g==GUID_Spring)|| (g==GUID_Damper)|| (g==GUID_Inertia)|| (g==GUID_Friction)){
  1128. if (realEffect->cbTypeSpecificParams ==sizeof(DICONDITION)*2){
  1129. memcpy(&(cover->conditionY),realEffect->lpvTypeSpecificParams,sizeof(DICONDITION)*2);
  1130. cover->conditionFlags=DICONDITION_USE_BOTH_AXIS;
  1131. }
  1132. else{
  1133. memcpy(&(cover->conditionX),realEffect->lpvTypeSpecificParams,sizeof(DICONDITION));
  1134. cover->conditionFlags=DICONDITION_USE_DIRECTION;
  1135. }
  1136. }
  1137. else if (g==GUID_RampForce){
  1138. memcpy(&(cover->rampForce),realEffect->lpvTypeSpecificParams,sizeof(DIRAMPFORCE));
  1139. }
  1140. }
  1141. return S_OK;
  1142. }
  1143. #define MYVARIANTINIT(inArg,puser) \
  1144. VariantInit(puser); \
  1145. user.vt=VT_UNKNOWN; \
  1146. user.punkVal = inArg; \
  1147. user.punkVal->AddRef();