Forum > DirectX

IDirect3D9.CreateDevice() fails in 64 bit

(1/1)

Igor Kokarev:
CreateDevice() in IDirect3D9 fails with D3DERR_INVALIDCALL in 64 bit.

In 32 bit same code works fine.

I attach a simple Lazarus test project in a ZIP (see below the link). DirectX9 headers for FPC where downloaded from clootie.ru

Lazarus 1.8.4 / fpc 3.0.4 / Windows 10 v1803 64 bit.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit MainUnit; {$mode objfpc}{$H+} interface uses  Types, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,  StdCtrls,  Direct3D9; const  {$IFDEF DXDEBUG}  Local_D3D_SDK_VERSION   = (32 or $80000000);  {$ELSE}  Local_D3D_SDK_VERSION   = 32;  {$ENDIF} type  { TForm1 }  TForm1 = class(TForm)    Memo1: TMemo;    procedure FormClick(Sender: TObject);    procedure FormCreate(Sender: TObject);    procedure FormKeyPress(Sender: TObject; var Key: char);    procedure Log(const S : string; N : Int64);    procedure Init3D;  private    fD3D               : IDirect3D9;    fDevice            : IDirect3DDevice9;  public  end; var  Form1: TForm1; implementation {$R *.lfm}{ TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  Caption:='Fpc'+IntToStr(SizeOf(Pointer)*8);  Init3D;end; procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);begin  if Key=#13 then Self.Click;end; procedure TForm1.Init3D;var  R             : TRect;  W, H          : Integer;  PresParams    : TD3DPresentParameters;  res           : HResult;begin  R:=Self.BoundsRect;  W:=(R.Right-R.Left);  H:=(R.Bottom-R.Top);   fD3D:=Direct3DCreate9(Local_D3D_SDK_Version);  Log('IDirect3D ',UIntPtr(fD3D));   if not Assigned(fD3D) then Exit;   FillChar(PresParams, SizeOf(PresParams), 0);  PresParams.Windowed:=True;  PresParams.PresentationInterval:=D3DPRESENT_INTERVAL_DEFAULT;  PresParams.SwapEffect:=D3DSWAPEFFECT_COPY;  PresParams.BackBufferCount:=1;   PresParams.BackBufferWidth:=W;  PresParams.BackBufferHeight:=H;  PresParams.BackBufferFormat:=D3DFMT_X8R8G8B8; //_D3DFORMAT(Params.DisplayMode.PixelFormat);   Log('Self.Handle ', Self.Handle);   res := fD3D.CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Self.Handle,      D3DCREATE_MULTITHREADED or D3DCREATE_FPU_PRESERVE or D3DCREATE_SOFTWARE_VERTEXPROCESSING,      @PresParams, fDevice );   Log('Create Device, HResult ',res );  if res=D3D_OK then Log('IDirect3DDevice9 ', UIntPtr(fDevice) );end;  procedure TForm1.FormClick(Sender: TObject);var  R             : TRect;  W, H          : Integer;begin  if fDevice=nil then Exit;  if Memo1.Visible then begin    Memo1.Visible:=False;    Self.Update;  end;   R:=Self.BoundsRect;  W:=(R.Right-R.Left);  H:=(R.Bottom-R.Top);   fDevice.BeginScene;   R:=Rect(0,0,W,H div 3);  fDevice.Clear(1, @R, D3DCLEAR_TARGET, $00FFFFFF, 0, 0);   R.Top:=R.Bottom; R.Bottom:=H*2 div 3;  fDevice.Clear(1, @R, D3DCLEAR_TARGET, $000000FF, 0, 0);   R.Top:=R.Bottom; R.Bottom:=H;  fDevice.Clear(1, @R, D3DCLEAR_TARGET, $00FF0000, 0, 0);   fDevice.EndScene;   R:=Rect(0,0,W,H);  fDevice.Present( @R, @R, 0, nil );end; procedure TForm1.Log(const S : string; N : Int64);begin  Form1.Memo1.Lines.Add(S+IntToStr(N));;end; end. 

Igor Kokarev:
I found that if I replace all "packed record" to "record" in DirectX headers my app starts to work.

It seems to be compatiblity with 64 bit in current DirectX headers from clootie.

Navigation

[0] Message Index

Go to full version