Jump to content
  • Advertisement
Sign in to follow this  
prux

Direct3D freezes from DLL

This topic is 2742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey all,

in this example, I need to hook an app (who could have thought that? :crazy:) with the attached code I need a window and Direct3D, since it must render to a standallone window (and must D3D).
The attaching into it is OK. But when I try to get rid of it, D3D freezes.

{$IMAGEBASE $57000000}
{$APPTYPE CONSOLE}
{$R+,D+,Q+,S+,I+}
program Application;
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, MadCodeHook;

var
si : TStartupInfo;
pi : TProcessInformation;

begin
FillChar (si, sizeof(si), 0);
CreateProcessEx (nil, 'hookme.exe', nil, nil, false, 0, nil, nil, si, pi, 'hook.dll');
end.[/quote]

{$R+,D+,Q+,S+,I+}
library Hook;

uses
Windows,
Dialogs,
Sysutils,
Forms,
Direct3D9;

var
myForm : TForm = nil;
VideoCardInfo : TD3DDISPLAYMODE;
D3DInit : TD3DPRESENT_PARAMETERS;
mode : TD3DDisplayMode;
Direct3D : IDirect3D9;
D3DDevice : IDirect3DDevice9;
D3DBBuffer : IDirect3DSurface9;

procedure DllMain(dwReason: DWord);
begin
if (dwReason = DLL_PROCESS_ATTACH) then
begin
MyForm:= TForm.Create (nil);
MyForm.Width:= 640;
MyForm.Height:= 480;
MyForm.Position:= poScreenCenter;
MyForm.Show;

Direct3D:= Direct3DCreate9 (D3D_SDK_VERSION);
Direct3D.GetAdapterDisplayMode (D3DADAPTER_DEFAULT, mode);
FillChar (VideoCardInfo, SizeOf(VideoCardInfo), 0);
FillChar (D3DInit, SizeOf(D3DInit), 0);
WITH D3DInit DO
BEGIN
Windowed:= TRUE;
BackBufferWidth:= 640;
BackBufferHeight:= 480;
BackBufferCount:= 1;
BackBufferFormat:= Mode.Format;
SwapEffect:= D3DSWAPEFFECT_DISCARD;
hDeviceWindow:= MyForm.Handle;
END;
Direct3D.CreateDevice (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, MyForm.Handle, D3DCREATE_SOFTWARE_VERTEXPROCESSING, @D3DInit, D3DDevice);
D3DDevice.GetBackBuffer (0, 0, D3DBACKBUFFER_TYPE_MONO, D3DBBuffer);
end;

if (dwReason = DLL_PROCESS_DETACH) then
begin
D3DBBuffer:= nil; messagebeep (1000); sleep (1000);
D3DDevice:= nil; <-- FREEZE HERE messagebeep (1000); sleep (1000);
Direct3D:= nil; messagebeep (1000); sleep (1000);
if Assigned(MyForm) then MyForm.Free;
MyForm:= nil;
end;
end;

begin
DllProc := TDLLProc(@DllMain);
DllMain (DLL_PROCESS_ATTACH);
end.[/quote]

So it freezes at DLL_PROCESS_DETACH part, the hooked application remains in the memory. Does anyone know why? Very simple and short program and I cant figure it out

Share this post


Link to post
Share on other sites
Advertisement
You're too a lot of stuff in PROCESS_ATTACH that you're not allowed to, look into what you can and cannot do in it.
Loading another dll for example, is a big no no.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!