DirectInput DLL

Started by
4 comments, last by njpaul 18 years, 10 months ago
Im trying to create a Direct X Wrapper based on dll , however Ive ran in a problem Whn I try to set the cooperative level I need to get a HWND pointer, which I dont have because Im using a dll. Right now Im using the FindWindow command But If I change the name of my test to anything other than DLL demo it wont work.

  if( FAILED( hr = g_pJoystick->SetCooperativeLevel( FindWindow(NULL, "Dll Demo"), DISCL_EXCLUSIVE | 
                                                             DISCL_FOREGROUND ) ) )
        return hr;
How can I get the HWND of the window that is calling my DLL ?
Advertisement
The most obvious, direct, and recommended approach is to make the caller pass it to the DLL. Additionally, this gives more control to the caller, because he can have many windows, and select one of them and pass it to you.

On a sidenote, if you're writing a wrapper and you're not aiming for cross-platform development (you're using a DLL already...) make it as thin as possible, or re-evaluate your need for a wrapper and drop it altogether if you don't need it. Focus on what you want to get the game done, the input system itself, not wrappers.

Hmm.. good answer thanks, but lets suppose I need to get the Parent HWND is there anyway to do that?
Assuming that you have access to a HWND, then you can always get the parent through the GetParent function.
Quote:Original post by Azrael
Hmm.. good answer thanks, but lets suppose I need to get the Parent HWND is there anyway to do that?

I don't know for sure, but I don't think so. You can't even guarantee there's a HWND; the DLL could be loaded by an application that created no windows.

Try using __declspec(dllimport) to pass things into the dll.

MSDN documentation

This topic is closed to new replies.

Advertisement