Sign in to follow this  
EGD Eric

Problem: Get application window handle from a .dll

Recommended Posts

OK, here's the problem: I've got a .dll, and the source code to said .dll. I don't have the source code to the main game, but the dll contains most of the game's logic, just none of the rendering code. I want to add some functions to this dll, but some of them require a handle to the window, and the application (a HWND & a HINSTANCE). I thought maybe some of you more knowledgeable (esp. with dlls) might have a clue as to how to get the window & application handles. PS, if anyone's wondering what I'm doing, I'm using the Quake 4 SDK. It comes with a project. You can modify the code to this project, and build a new dll, which the main game's exe supposedly calls functions from. Thanks in advance for any advice someone gives, even if its to tell me that this isn't possible!

Share this post


Link to post
Share on other sites
You can get the application's HINSTANCE via GetModuleHandle(NULL);. As for the window handle, you could use EnumWindows to enumerate all th windows and find the game one. Alternatively, if you know the window classname, you can use FindWindow.

That's assuming there's only one instance of the application running. If there's more than one, things get a bit more tricky - the only way I can think of doing it is by using GetWindowLong to get the HINSTANCE of the application that created the window, then enumerate all loaded DLLs to find your own DLL, then use something like WriteProcessMemory to write into your own running DLL to see if "this" is the same DLL you're running in at the moment.

Share this post


Link to post
Share on other sites
Quote:
Original post by EGD Eric
neat stuff, might come in handy. Question: What exactly is a "top level window"? how does that differ from any other window?


A top-level window is one whose parent is NULL (that is, the 8th parameter to CreateWindow). As opposed to a child window (e.g. a button, listview, etc -- these are child windows).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this