function InitD3D: HRESULT; const wc: TWndClassEx = ( cbSize: SizeOf(TWndClassEx); style: CS_CLASSDC; lpfnWndProc: @MsgProcD3D; cbClsExtra: 0; cbWndExtra: 0; hInstance: 0; // - filled later hIcon: 0; hCursor: 0; hbrBackground: 0; lpszMenuName: nil; lpszClassName: 'Grey'; hIconSm: 0); var d3dpp: TD3DPresentParameters; begin RegisterClassEx(wc); g_hWnd := CreateWindowEx(WS_EX_APPWINDOW, PChar('Grey'), // class name nil, // title for our window (appears in the titlebar) WS_OVERLAPPED or WS_CAPTION or WS_SYSMENU or WS_MINIMIZEBOX, 0, 0, // initial x, y coordinate 1, 1, // width and height of the window HWND_DESKTOP, // no parent window. 0, // no menu 0, // no creator nil ); // extra data if g_hWnd = 0 then RaiseLastOSError; Result:= E_FAIL; // Create the D3D object. g_pD3D := Direct3DCreate9(D3D_SDK_VERSION); if (g_pD3D = nil) then begin PInteger(0)^ := 1; Exit; end; // Set up the structure used to create the D3DDevice FillChar(d3dpp, SizeOf(d3dpp), 0); d3dpp.Windowed := True; d3dpp.SwapEffect := D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat := D3DFMT_UNKNOWN; // Create the D3DDevice Result:= g_pD3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, @d3dpp, g_pd3dDevice); if FAILED(Result) then begin PInteger(0)^ := 1; Result:= E_FAIL; Exit; end; g_RenderFunc := PPointer(PInteger(g_pd3dDevice)^ + $44)^; g_RenderHook := TMultiHook.Create; g_RenderHook.DetourHook(g_RenderFunc, @MyRenderFunc); end;