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.

877 lines
22 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: ddraw7obj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // dDrawObj.cpp : Implementation of CDirectApp and DLL registration.
  11. #include "stdafx.h"
  12. #include "Direct.h"
  13. #include "dms.h"
  14. #include "dDraw7Obj.h"
  15. #include "ddClipperObj.h"
  16. #include "ddSurface7Obj.h"
  17. #include "ddPaletteObj.h"
  18. #include "ddEnumModesObj.h"
  19. #include "ddEnumSurfacesObj.h"
  20. #include "d3d7Obj.h"
  21. #include "ddIdentifierObj.h"
  22. extern BOOL is4Bit;
  23. extern HRESULT CopyInDDSurfaceDesc2(DDSURFACEDESC2 *,DDSurfaceDesc2*);
  24. extern HRESULT CopyOutDDSurfaceDesc2(DDSurfaceDesc2*,DDSURFACEDESC2 *);
  25. ///////////////////////////////////////////////////////////////////
  26. // InternalAddRef
  27. ///////////////////////////////////////////////////////////////////
  28. DWORD C_dxj_DirectDraw7Object::InternalAddRef(){
  29. DWORD i;
  30. i=CComObjectRoot::InternalAddRef();
  31. DPF2(1,"DDraw7 [%d] AddRef %d \n",creationid,i);
  32. return i;
  33. }
  34. ///////////////////////////////////////////////////////////////////
  35. // InternalRelease
  36. ///////////////////////////////////////////////////////////////////
  37. DWORD C_dxj_DirectDraw7Object::InternalRelease(){
  38. DWORD i;
  39. i=CComObjectRoot::InternalRelease();
  40. DPF2(1,"DDraw4 [%d] Release %d \n",creationid,i);
  41. return i;
  42. }
  43. ///////////////////////////////////////////////////////////////////
  44. // C_dxj_DirectDraw7Object
  45. ///////////////////////////////////////////////////////////////////
  46. C_dxj_DirectDraw7Object::C_dxj_DirectDraw7Object(){
  47. DPF1(1,"Constructor Creation DirectDraw7Object[%d] \n ",g_creationcount);
  48. m__dxj_DirectDraw7= NULL;
  49. parent = NULL;
  50. pinterface = NULL;
  51. nextobj = g_dxj_DirectDraw7;
  52. creationid = ++g_creationcount;
  53. g_dxj_DirectDraw7 = (void *)this;
  54. m_hwnd=NULL;
  55. }
  56. ///////////////////////////////////////////////////////////////////
  57. // ~C_dxj_DirectDraw7Object
  58. ///////////////////////////////////////////////////////////////////
  59. C_dxj_DirectDraw7Object::~C_dxj_DirectDraw7Object()
  60. {
  61. DPF(1,"Entering ~DirectDraw7Object destructor \n");
  62. C_dxj_DirectDraw7Object *prev=NULL;
  63. for(C_dxj_DirectDraw7Object *ptr=(C_dxj_DirectDraw7Object *)g_dxj_DirectDraw7; ptr; ptr=(C_dxj_DirectDraw7Object *)ptr->nextobj)
  64. {
  65. if(ptr == this)
  66. {
  67. if(prev)
  68. prev->nextobj = ptr->nextobj;
  69. else
  70. g_dxj_DirectDraw7 = (void*)ptr->nextobj;
  71. DPF(1,"DirectDraw7Object found in g_dxj list now removed\n");
  72. break;
  73. }
  74. prev = ptr;
  75. }
  76. if(m__dxj_DirectDraw7){
  77. int count = IUNK(m__dxj_DirectDraw7)->Release();
  78. #ifdef DEBUG
  79. char buffer[256];
  80. wsprintf(buffer,"DirectX IDirectDraw7 Ref count [%d] \n",count);
  81. #endif
  82. if(count==0) m__dxj_DirectDraw7 = NULL;
  83. }
  84. if(parent) IUNK(parent)->Release();
  85. }
  86. ///////////////////////////////////////////////////////////////////
  87. // InternalGetObject
  88. // InternalSetObject
  89. // restoreDisplayMode
  90. // flipToGDISurface
  91. // setDisplayMode
  92. ///////////////////////////////////////////////////////////////////
  93. GETSET_OBJECT(_dxj_DirectDraw7);
  94. PASS_THROUGH_R(_dxj_DirectDraw7, restoreDisplayMode, RestoreDisplayMode)
  95. PASS_THROUGH_R(_dxj_DirectDraw7, flipToGDISurface, FlipToGDISurface)
  96. PASS_THROUGH5_R(_dxj_DirectDraw7, setDisplayMode, SetDisplayMode, long,long,long,long,long)
  97. ///////////////////////////////////////////////////////////////////
  98. // getMonitorFrequency
  99. ///////////////////////////////////////////////////////////////////
  100. STDMETHODIMP C_dxj_DirectDraw7Object::getMonitorFrequency(long *ret)
  101. {
  102. HRESULT hr;
  103. hr=m__dxj_DirectDraw7->GetMonitorFrequency((DWORD*)ret);
  104. return hr;
  105. }
  106. ///////////////////////////////////////////////////////////////////
  107. // getGDISurface
  108. ///////////////////////////////////////////////////////////////////
  109. STDMETHODIMP C_dxj_DirectDraw7Object::getGDISurface(I_dxj_DirectDrawSurface7 **rv)
  110. {
  111. LPDIRECTDRAWSURFACE7 lp4=NULL;
  112. if ( is4Bit )
  113. return E_FAIL;
  114. *rv = NULL;
  115. HRESULT hr = DD_OK;
  116. if( ( hr=m__dxj_DirectDraw7->GetGDISurface(&lp4) ) != DD_OK)
  117. return hr;
  118. INTERNAL_CREATE(_dxj_DirectDrawSurface7, lp4, rv);
  119. return hr;
  120. }
  121. ///////////////////////////////////////////////////////////////////
  122. // getVerticalBlankStatus
  123. ///////////////////////////////////////////////////////////////////
  124. STDMETHODIMP C_dxj_DirectDraw7Object::getVerticalBlankStatus( long *status)
  125. {
  126. if ( is4Bit )
  127. return E_FAIL;
  128. return m__dxj_DirectDraw7->GetVerticalBlankStatus((int *)status);
  129. }
  130. ///////////////////////////////////////////////////////////////////
  131. // setCooperativeLevel
  132. ///////////////////////////////////////////////////////////////////
  133. STDMETHODIMP C_dxj_DirectDraw7Object::setCooperativeLevel( HWnd hwn, long flags)
  134. {
  135. if ( is4Bit )
  136. return E_FAIL;
  137. m_hwnd = (HWND)hwn;
  138. return m__dxj_DirectDraw7->SetCooperativeLevel((HWND)hwn, (DWORD)flags);
  139. }
  140. ///////////////////////////////////////////////////////////////////
  141. // waitForVerticalBlank
  142. ///////////////////////////////////////////////////////////////////
  143. STDMETHODIMP C_dxj_DirectDraw7Object::waitForVerticalBlank(long flags,long handle, long *status)
  144. {
  145. if ( is4Bit )
  146. return E_FAIL;
  147. *status = m__dxj_DirectDraw7->WaitForVerticalBlank(flags, (void *)handle);
  148. return S_OK;
  149. }
  150. ///////////////////////////////////////////////////////////////////
  151. // createClipper
  152. ///////////////////////////////////////////////////////////////////
  153. STDMETHODIMP C_dxj_DirectDraw7Object::createClipper(long flags, I_dxj_DirectDrawClipper **val)
  154. {
  155. if ( is4Bit )
  156. return E_FAIL;
  157. DPF1(1,"enter DDraw4[%d]::createClipper ",creationid);
  158. //
  159. // need to create one of MY surfaces!
  160. //
  161. LPDIRECTDRAWCLIPPER ddc;
  162. HRESULT hr = DD_OK;
  163. if( (hr=m__dxj_DirectDraw7->CreateClipper( flags, &ddc, NULL)) != DD_OK )
  164. return hr;
  165. INTERNAL_CREATE(_dxj_DirectDrawClipper, ddc, val);
  166. DPF1(1,"exit DDraw4[%d]::createClipper ",creationid);
  167. return hr;
  168. }
  169. ///////////////////////////////////////////////////////////////////
  170. // createPalette
  171. ///////////////////////////////////////////////////////////////////
  172. STDMETHODIMP C_dxj_DirectDraw7Object::createPalette(long flags, SAFEARRAY **pe, I_dxj_DirectDrawPalette **val)
  173. {
  174. LPPALETTEENTRY ppe;
  175. if ( is4Bit )
  176. return E_FAIL;
  177. if (!ISSAFEARRAY1D(pe,(DWORD)256)) return E_INVALIDARG;
  178. ppe = (LPPALETTEENTRY)((SAFEARRAY*)*pe)->pvData;
  179. LPDIRECTDRAWPALETTE ddp;
  180. HRESULT hr = DD_OK;
  181. *val = NULL;
  182. if( (hr=m__dxj_DirectDraw7->CreatePalette( flags, (LPPALETTEENTRY)ppe, &ddp, NULL)) == DD_OK )
  183. {
  184. INTERNAL_CREATE( _dxj_DirectDrawPalette, ddp, val);
  185. }
  186. return hr;
  187. }
  188. ///////////////////////////////////////////////////////////////////
  189. // createSurface
  190. ///////////////////////////////////////////////////////////////////
  191. STDMETHODIMP C_dxj_DirectDraw7Object::createSurface(DDSurfaceDesc2 *dd, I_dxj_DirectDrawSurface7 **retval)
  192. {
  193. HRESULT retv;
  194. LPDIRECTDRAWSURFACE7 dds7; // DirectX object pointer
  195. DDSURFACEDESC2 ddsd;
  196. DPF1(1,"enter DDraw7[%d]::createSurface ",creationid);
  197. if ( is4Bit )
  198. return E_FAIL;
  199. if(! (dd && retval) )
  200. return E_POINTER;
  201. CopyInDDSurfaceDesc2(&ddsd,dd);
  202. //docdoc: CreateSurface returns error if 'punk' is anything but NULL
  203. retv = m__dxj_DirectDraw7->CreateSurface( &ddsd, &dds7, NULL);
  204. if FAILED(retv) return retv;
  205. INTERNAL_CREATE(_dxj_DirectDrawSurface7, dds7, retval);
  206. dd->lpSurface = NULL;
  207. DPF1(1,"exit DDraw7[%d]::createSurface ",creationid);
  208. return S_OK;
  209. }
  210. ///////////////////////////////////////////////////////////////////
  211. // duplicateSurface
  212. ///////////////////////////////////////////////////////////////////
  213. STDMETHODIMP C_dxj_DirectDraw7Object::duplicateSurface(I_dxj_DirectDrawSurface7 *ddIn, I_dxj_DirectDrawSurface7 **ddOut)
  214. {
  215. HRESULT retval;
  216. if ( is4Bit )
  217. return E_FAIL;
  218. //
  219. // need to create one of MY surfaces!
  220. //
  221. LPDIRECTDRAWSURFACE7 lpddout7=NULL;
  222. DO_GETOBJECT_NOTNULL( LPDIRECTDRAWSURFACE7, lpddin, ddIn);
  223. if( (retval = m__dxj_DirectDraw7->DuplicateSurface(lpddin, &lpddout7)) != DD_OK )
  224. return retval;
  225. INTERNAL_CREATE( _dxj_DirectDrawSurface7, lpddout7, ddOut);
  226. return S_OK;
  227. }
  228. ///////////////////////////////////////////////////////////////////
  229. // getCaps
  230. ///////////////////////////////////////////////////////////////////
  231. STDMETHODIMP C_dxj_DirectDraw7Object::getCaps(DDCaps *driverCaps, DDCaps *HELcaps)
  232. {
  233. if ( is4Bit )
  234. return E_FAIL;
  235. if (!driverCaps) return E_INVALIDARG;
  236. if (!HELcaps) return E_INVALIDARG;
  237. ((DDCAPS*)driverCaps)->dwSize=sizeof(DDCAPS);
  238. ((DDCAPS*)HELcaps)->dwSize=sizeof(DDCAPS);
  239. HRESULT hr = m__dxj_DirectDraw7->GetCaps((DDCAPS*)driverCaps, (DDCAPS*)HELcaps);
  240. return hr;
  241. }
  242. ///////////////////////////////////////////////////////////////////
  243. // getDisplayMode
  244. ///////////////////////////////////////////////////////////////////
  245. STDMETHODIMP C_dxj_DirectDraw7Object::getDisplayMode(DDSurfaceDesc2 *desc)
  246. {
  247. HRESULT retval;
  248. DDSURFACEDESC2 ddsd;
  249. if (!desc) return E_INVALIDARG;
  250. CopyInDDSurfaceDesc2(&ddsd,desc);
  251. retval = m__dxj_DirectDraw7->GetDisplayMode(&ddsd);
  252. if( retval != S_OK)
  253. return retval;
  254. CopyOutDDSurfaceDesc2(desc,&ddsd);
  255. desc->lpSurface = NULL;
  256. return S_OK;
  257. }
  258. ///////////////////////////////////////////////////////////////////
  259. // getAvailableTotalMem
  260. ///////////////////////////////////////////////////////////////////
  261. STDMETHODIMP C_dxj_DirectDraw7Object::getAvailableTotalMem(DDSCaps2 *ddsCaps, long *m)
  262. {
  263. return m__dxj_DirectDraw7->GetAvailableVidMem((LPDDSCAPS2)ddsCaps, (unsigned long *)m, NULL);
  264. }
  265. ///////////////////////////////////////////////////////////////////
  266. // getFreeMem
  267. ///////////////////////////////////////////////////////////////////
  268. STDMETHODIMP C_dxj_DirectDraw7Object::getFreeMem(DDSCaps2 *ddsCaps, long *m)
  269. {
  270. return m__dxj_DirectDraw7->GetAvailableVidMem((LPDDSCAPS2)ddsCaps, NULL, (unsigned long *)m);
  271. }
  272. ///////////////////////////////////////////////////////////////////
  273. // getDirect3D
  274. ///////////////////////////////////////////////////////////////////
  275. STDMETHODIMP C_dxj_DirectDraw7Object::getDirect3D(I_dxj_Direct3d7 **retval)
  276. {
  277. LPDIRECT3D7 lpD3D;
  278. HRESULT hr = DD_OK;
  279. if ( is4Bit )
  280. return E_FAIL;
  281. if( (hr=m__dxj_DirectDraw7->QueryInterface(IID_IDirect3D7, (void**) &lpD3D)) != DD_OK)
  282. return hr;
  283. INTERNAL_CREATE(_dxj_Direct3d7, lpD3D, retval);
  284. return hr;
  285. }
  286. ///////////////////////////////////////////////////////////////////
  287. // getNumFourCCCodes
  288. ///////////////////////////////////////////////////////////////////
  289. STDMETHODIMP C_dxj_DirectDraw7Object::getNumFourCCCodes(long *retval)
  290. {
  291. return m__dxj_DirectDraw7->GetFourCCCodes((DWORD*)retval, NULL);
  292. }
  293. ///////////////////////////////////////////////////////////////////
  294. // getScanLine
  295. ///////////////////////////////////////////////////////////////////
  296. STDMETHODIMP C_dxj_DirectDraw7Object::getScanLine(long *lines, long *status)
  297. {
  298. *status = (long)m__dxj_DirectDraw7->GetScanLine((DWORD*)lines);
  299. return S_OK;
  300. }
  301. ///////////////////////////////////////////////////////////////////
  302. // loadPaletteFromBitmap
  303. ///////////////////////////////////////////////////////////////////
  304. STDMETHODIMP C_dxj_DirectDraw7Object::loadPaletteFromBitmap(BSTR bName, I_dxj_DirectDrawPalette **retval)
  305. {
  306. USES_CONVERSION;
  307. IDirectDrawPalette* ddpal;
  308. int i;
  309. int n;
  310. int fh;
  311. HRSRC h;
  312. LPBITMAPINFOHEADER lpbi;
  313. PALETTEENTRY ape[256];
  314. RGBQUAD * prgb;
  315. HRESULT hr=S_OK;
  316. if ( is4Bit )
  317. return E_FAIL;
  318. LPCTSTR szBitmap = W2T(bName);
  319. for (i=0; i<256; i++) // build a 332 palette as the default
  320. {
  321. ape[i].peRed = (BYTE)(((i >> 5) & 0x07) * 255 / 7);
  322. ape[i].peGreen = (BYTE)(((i >> 2) & 0x07) * 255 / 7);
  323. ape[i].peBlue = (BYTE)(((i >> 0) & 0x03) * 255 / 3);
  324. ape[i].peFlags = (BYTE)0;
  325. }
  326. //
  327. // get a pointer to the bitmap resource.
  328. //
  329. if (szBitmap && (h = FindResource(NULL, szBitmap, RT_BITMAP)))
  330. {
  331. lpbi = (LPBITMAPINFOHEADER)LockResource(LoadResource(NULL, h));
  332. if (!lpbi){
  333. DPF(1,"lock resource failed\n");
  334. }
  335. prgb = (RGBQUAD*)((BYTE*)lpbi + lpbi->biSize);
  336. if (lpbi == NULL || lpbi->biSize < sizeof(BITMAPINFOHEADER))
  337. n = 0;
  338. else if (lpbi->biBitCount > 8)
  339. n = 0;
  340. else if (lpbi->biClrUsed == 0)
  341. n = 1 << lpbi->biBitCount;
  342. else
  343. n = lpbi->biClrUsed;
  344. //
  345. // a DIB color table has its colors stored BGR not RGB
  346. // so flip them around.
  347. //
  348. for(i=0; i<n; i++ )
  349. {
  350. ape[i].peRed = prgb[i].rgbRed;
  351. ape[i].peGreen = prgb[i].rgbGreen;
  352. ape[i].peBlue = prgb[i].rgbBlue;
  353. ape[i].peFlags = 0;
  354. }
  355. }
  356. else if (szBitmap && (fh = _lopen(szBitmap, OF_READ)) != -1)
  357. {
  358. BITMAPFILEHEADER bf;
  359. BITMAPINFOHEADER bi;
  360. _lread(fh, &bf, sizeof(bf));
  361. _lread(fh, &bi, sizeof(bi));
  362. _lread(fh, ape, sizeof(ape));
  363. _lclose(fh);
  364. if (bi.biSize != sizeof(BITMAPINFOHEADER))
  365. n = 0;
  366. else if (bi.biBitCount > 8)
  367. n = 0;
  368. else if (bi.biClrUsed == 0)
  369. n = 1 << bi.biBitCount;
  370. else
  371. n = bi.biClrUsed;
  372. //
  373. // a DIB color table has its colors stored BGR not RGB
  374. // so flip them around.
  375. //
  376. for(i=0; i<n; i++ )
  377. {
  378. BYTE r = ape[i].peRed;
  379. ape[i].peRed = ape[i].peBlue;
  380. ape[i].peBlue = r;
  381. }
  382. }
  383. m__dxj_DirectDraw7->CreatePalette(DDPCAPS_8BIT, ape, &ddpal, NULL);
  384. if( ddpal )
  385. {
  386. INTERNAL_CREATE(_dxj_DirectDrawPalette, ddpal, retval);
  387. }
  388. else
  389. {
  390. //
  391. // no object, set the return value to NULL as well.
  392. //
  393. *retval = NULL;
  394. hr = E_FAIL;
  395. }
  396. return hr;
  397. }
  398. ///////////////////////////////////////////////////////////////////
  399. // createSurfaceFromFile
  400. ///////////////////////////////////////////////////////////////////
  401. STDMETHODIMP C_dxj_DirectDraw7Object::createSurfaceFromFile(BSTR file, DDSurfaceDesc2 *desc, I_dxj_DirectDrawSurface7 **surf)
  402. {
  403. DPF1(1,"enter DDraw7[%d]::createSurfaceFromFile ",creationid);
  404. HDC hdc;
  405. HDC hdcImage;
  406. BITMAP bm;
  407. HRESULT hr;
  408. HBITMAP hbm;
  409. HRESULT retv;
  410. LPDIRECTDRAWSURFACE7 dds7; // DirectX object pointer
  411. LPSTR szFileName=NULL;
  412. int width=0;
  413. int height=0;
  414. if ( is4Bit )
  415. return E_FAIL;
  416. if(! (desc && surf) )
  417. return E_POINTER;
  418. USES_CONVERSION;
  419. szFileName=W2T(file);
  420. //If width and height are zero then we will generate our own width and
  421. //height from the bitmap.
  422. //The LoadImage api however doesnt work propery without size params
  423. //Consider there must be a way to make it work.
  424. if ((desc->lWidth!=0)&&(desc->lHeight!=0)&&(desc->lFlags & DDSD_WIDTH)&&(desc->lFlags & DDSD_HEIGHT))
  425. {
  426. width=desc->lWidth ;
  427. height=desc->lHeight;
  428. }
  429. if (desc->lFlags==0) {
  430. desc->lFlags=DDSD_CAPS;
  431. ((DDSURFACEDESC*)desc)->ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN;
  432. }
  433. //hbm = (HBITMAP)LoadImageW((HINSTANCE)NULL, file, IMAGE_BITMAP,
  434. // width, height,
  435. // LR_LOADFROMFILE|LR_CREATEDIBSECTION);
  436. hbm = (HBITMAP)LoadImage((HINSTANCE)NULL, szFileName, IMAGE_BITMAP,
  437. width, height,
  438. LR_LOADFROMFILE|LR_CREATEDIBSECTION);
  439. DWORD dwErr=GetLastError();
  440. if (!hbm){
  441. //often users pass in width and height in twips and not pixels
  442. //loadimage compails and returns ERROR_NOT_ENOUGH_MEMORY
  443. if (dwErr==ERROR_NOT_ENOUGH_MEMORY)
  444. {
  445. return E_OUTOFMEMORY;
  446. }
  447. else if (dwErr==ERROR_INVALID_PARAMETER)
  448. {
  449. return E_INVALIDARG;
  450. }
  451. else {
  452. return CTL_E_FILENOTFOUND;
  453. }
  454. }
  455. // get size of the bitmap
  456. //
  457. GetObject(hbm, sizeof(bm), &bm); // get size of bitmap
  458. width=bm.bmWidth;
  459. height=bm.bmHeight;
  460. desc->lFlags = desc->lFlags | DDSD_WIDTH | DDSD_HEIGHT;
  461. if ((desc->lWidth==0)||(desc->lHeight==0))
  462. {
  463. desc->lWidth =width;
  464. desc->lHeight =height;
  465. }
  466. DDSURFACEDESC2 ddsd;
  467. CopyInDDSurfaceDesc2(&ddsd,desc);
  468. if( (retv = m__dxj_DirectDraw7->CreateSurface(&ddsd, &dds7, NULL)) != DD_OK )
  469. return retv;
  470. CopyOutDDSurfaceDesc2(desc,&ddsd);
  471. INTERNAL_CREATE(_dxj_DirectDrawSurface7, dds7, surf);
  472. desc->lpSurface = NULL;
  473. //
  474. // make sure this surface is restored.
  475. //
  476. dds7->Restore();
  477. //
  478. // select bitmap into a memoryDC so we can use it.
  479. //
  480. hdcImage = CreateCompatibleDC(NULL);
  481. SelectObject(hdcImage, hbm);
  482. if (!hdcImage){
  483. DeleteObject(hbm);
  484. return E_FAIL;
  485. }
  486. if ((hr = dds7->GetDC(&hdc)) == DD_OK)
  487. {
  488. StretchBlt(hdc, 0, 0, desc->lWidth , desc->lHeight, hdcImage,
  489. 0, 0, width, height, SRCCOPY);
  490. dds7->ReleaseDC(hdc);
  491. }
  492. DeleteDC(hdcImage);
  493. if (hbm) DeleteObject(hbm);
  494. DPF1(buffer,"exit DDraw7[%d]::createSurfaceFromFile",creationid);
  495. return S_OK;
  496. }
  497. ///////////////////////////////////////////////////////////////////
  498. // createSurfaceFromResource
  499. ///////////////////////////////////////////////////////////////////
  500. STDMETHODIMP C_dxj_DirectDraw7Object::createSurfaceFromResource(BSTR resFile, BSTR resourceName, DDSurfaceDesc2 *desc, I_dxj_DirectDrawSurface7 **surf)
  501. {
  502. DPF1(1,"enter DDraw4[%d]::createSurfaceFromResource ",creationid);
  503. if ( is4Bit )
  504. return E_FAIL;
  505. if(! (desc && surf) )
  506. return E_POINTER;
  507. HRESULT hr;
  508. HRSRC hres=NULL;
  509. HGLOBAL hglob=NULL;
  510. HDC hdc;
  511. HDC hdcImage;
  512. BITMAP bm;
  513. HBITMAP hbm;
  514. HRESULT retv;
  515. LPDIRECTDRAWSURFACE7 dds7; // DirectX object pointer
  516. LPSTR szResName=NULL;
  517. if (!resourceName) return E_INVALIDARG;
  518. if (!surf) return E_INVALIDARG;
  519. HMODULE hMod=NULL;
  520. USES_CONVERSION;
  521. if ((resFile) &&(resFile[0]!=0)){
  522. // NOTE:
  523. // seems that GetModuleHandleW is
  524. // always returning 0 on w98
  525. // converting to ansi first
  526. LPCTSTR pszName = W2T(resFile);
  527. hMod= GetModuleHandle(pszName);
  528. }
  529. else {
  530. hMod= GetModuleHandle(NULL);
  531. }
  532. LPCTSTR pszName2 = W2T(resourceName);
  533. //hbm = (HBITMAP)LoadImageW((HINSTANCE)hMod, resourceName,
  534. // IMAGE_BITMAP,
  535. // 0, 0,
  536. // LR_CREATEDIBSECTION);
  537. hbm = (HBITMAP)LoadImage((HINSTANCE)hMod,
  538. pszName2,
  539. IMAGE_BITMAP,
  540. 0, 0,
  541. LR_CREATEDIBSECTION);
  542. if (!hbm){
  543. //MessageBox(NULL,"FAILED ON LOAD IMAGE","TEST",MB_OK);
  544. return E_FAIL;
  545. }
  546. // get size of the bitmap
  547. //
  548. GetObject(hbm, sizeof(bm), &bm); // get size of bitmap
  549. DWORD width=bm.bmWidth;
  550. DWORD height=bm.bmHeight;
  551. desc->lFlags = desc->lFlags | DDSD_WIDTH | DDSD_HEIGHT;
  552. if ((desc->lWidth==0)||(desc->lHeight==0))
  553. {
  554. desc->lWidth =width;
  555. desc->lHeight =height;
  556. }
  557. DDSURFACEDESC2 ddsd;
  558. CopyInDDSurfaceDesc2(&ddsd,desc);
  559. if( (retv = m__dxj_DirectDraw7->CreateSurface(&ddsd, &dds7, NULL)) != DD_OK )
  560. return retv;
  561. CopyOutDDSurfaceDesc2(desc,&ddsd);
  562. INTERNAL_CREATE(_dxj_DirectDrawSurface7, dds7, surf);
  563. desc->lpSurface = NULL;
  564. //
  565. // make sure this surface is restored.
  566. //
  567. dds7->Restore();
  568. //
  569. // select bitmap into a memoryDC so we can use it.
  570. //
  571. hdcImage = CreateCompatibleDC(NULL);
  572. SelectObject(hdcImage, hbm);
  573. if (!hdcImage){
  574. DeleteObject(hbm);
  575. return E_FAIL;
  576. }
  577. if ((hr = dds7->GetDC(&hdc)) == DD_OK)
  578. {
  579. StretchBlt(hdc, 0, 0, desc->lWidth , desc->lHeight, hdcImage,
  580. 0, 0, width, height, SRCCOPY);
  581. dds7->ReleaseDC(hdc);
  582. }
  583. DeleteDC(hdcImage);
  584. if (hbm) DeleteObject(hbm);
  585. DPF1(1r,"exit DDraw4[%d]::createSurfaceFromFile",creationid);
  586. return S_OK;
  587. }
  588. ///////////////////////////////////////////////////////////////////
  589. // getFourCCCodes
  590. ///////////////////////////////////////////////////////////////////
  591. STDMETHODIMP C_dxj_DirectDraw7Object::getFourCCCodes(SAFEARRAY **ppsa)
  592. {
  593. DWORD count= ((SAFEARRAY*)*ppsa)->rgsabound[0].cElements;
  594. if ( ((SAFEARRAY*)*ppsa)->cDims!=1) return E_INVALIDARG;
  595. return m__dxj_DirectDraw7->GetFourCCCodes(&count,(DWORD*)((SAFEARRAY*)*ppsa)->pvData);
  596. }
  597. ///////////////////////////////////////////////////////////////////
  598. // getDisplayModesEnum
  599. ///////////////////////////////////////////////////////////////////
  600. STDMETHODIMP C_dxj_DirectDraw7Object::getDisplayModesEnum(
  601. /* [in] */ long flags,
  602. /* [in] */ DDSurfaceDesc2 *ddsd,
  603. /* [retval][out] */ I_dxj_DirectDrawEnumModes __RPC_FAR *__RPC_FAR *retval)
  604. {
  605. HRESULT hr;
  606. hr=C_dxj_DirectDrawEnumModesObject::create(m__dxj_DirectDraw7,flags, ddsd, retval);
  607. return hr;
  608. }
  609. ///////////////////////////////////////////////////////////////////
  610. // testCooperativeLevel
  611. ///////////////////////////////////////////////////////////////////
  612. STDMETHODIMP C_dxj_DirectDraw7Object::testCooperativeLevel(
  613. /* [in,out] */ long *status)
  614. {
  615. HRESULT hr;
  616. hr=m__dxj_DirectDraw7->TestCooperativeLevel();
  617. *status=(long)hr;
  618. return S_OK;
  619. }
  620. ///////////////////////////////////////////////////////////////////
  621. // restoreAllSurfaces
  622. ///////////////////////////////////////////////////////////////////
  623. STDMETHODIMP C_dxj_DirectDraw7Object::restoreAllSurfaces()
  624. {
  625. HRESULT hr;
  626. hr=m__dxj_DirectDraw7->RestoreAllSurfaces();
  627. return hr;
  628. }
  629. STDMETHODIMP C_dxj_DirectDraw7Object::getSurfaceFromDC(long hdc, I_dxj_DirectDrawSurface7 **ret)
  630. {
  631. HRESULT hr;
  632. LPDIRECTDRAWSURFACE7 pDDS=NULL;
  633. hr=m__dxj_DirectDraw7->GetSurfaceFromDC((HDC)hdc,&pDDS);
  634. if FAILED(hr) return hr;
  635. INTERNAL_CREATE(_dxj_DirectDrawSurface7,pDDS,ret);
  636. return hr;
  637. }
  638. STDMETHODIMP C_dxj_DirectDraw7Object::getSurfacesEnum(
  639. /* [in] */ long flags,
  640. /* [in] */ DDSurfaceDesc2 __RPC_FAR *desc,
  641. /* [retval][out] */ I_dxj_DirectDrawEnumSurfaces __RPC_FAR *__RPC_FAR *ret)
  642. {
  643. HRESULT hr=C_dxj_DirectDrawEnumSurfacesObject::create((I_dxj_DirectDraw7*)this , flags, desc,ret);
  644. return hr;
  645. }
  646. STDMETHODIMP C_dxj_DirectDraw7Object::getDeviceIdentifier(
  647. long flags,I_dxj_DirectDrawIdentifier **ret)
  648. {
  649. HRESULT hr;
  650. hr=C_dxj_DirectDrawIdentifierObject::Create(m__dxj_DirectDraw7,(DWORD)flags,ret);
  651. return hr;
  652. }