DirectInput on Max window handles


    Oct 18 2008 | 8:43 pm
    Hi all,
    I'm trying to use DirectInput for a windows external. I can successfully detect and create the device instance, but the problem lies with the following function:
    // Set the cooperative level to let DInput know how this device should // interact with the system and with other DInput applications. if( FAILED( hr = g_pDevice->SetCooperativeLevel( hWnd_, DISCL_EXCLUSIVE | DISCL_FOREGROUND ) ) )
    It always fails by returning E_HANDLE, which means according to the MSDN: "The HWND parameter is not a valid top-level window that belongs to the process."
    I've tried 2 different window handles. One from a named jit.window: jit_object_method(window, gensym("get_window_ptr"), &hWnd_);
    and one from the main application: hWnd_ = main_get_client();
    If I print the classname of hWnd_ (calling windows api function GetClassName()) it returns noise in the case of jit.window, and MDIClient in the case of main_get_client();
    I've also tried to set the flags to DISCL_NONEXCLUSIVE and DISCL_BACKGROUND.
    I'm out of ideas. Is there maybe something inherit to the max window handles that prevent me from using DirectInput devices?
    Thijs

    • Oct 18 2008 | 9:02 pm
      > I've tried 2 different window handles. One from a named jit.window: > jit_object_method(window, gensym("get_window_ptr"), &hWnd_);
      This should give you the HWND of the jit.window object. I don't have the docs in front of me, but perhaps you could check to see if that returned value is in fact a valid HWND before using it. If it's not, something's amiss.
      wes
    • Oct 18 2008 | 9:52 pm
      On Sat, Oct 18, 2008 at 11:02 PM, Wesley Smith wrote:
      > > I've tried 2 different window handles. One from a named jit.window: > > jit_object_method(window, gensym("get_window_ptr"), &hWnd_); > > This should give you the HWND of the jit.window object. I don't have > the docs in front of me, but perhaps you could check to see if that > returned value is in fact a valid HWND before using it. If it's not, > something's amiss. > > Hi Wes, I'm not sure what is the best way to test that. Like I said if I get the classname of the HWND, it appears to be noise for the HWND returned by get_window_ptr. The one from main_get_client() gives me "MDIClient".
      I just tried the GetWindowThreadProcessId(), and again on the main client this returns a valid number, on the jit.window HWND this returns 0.
      So I guess you are right about the HWND not being a valid window handle.
      If there is an easy workaround by creating a dummy window from my external directly, that would be ok for now too. I don't need to display anything in the window since the input device is to be used only by visually impaired people for now.
      If there's anything else I can test or if you want me to send you the code let me know.
      Best, Thijs
    • Oct 18 2008 | 10:14 pm
      The thing is, it should definitely give you a valid HWND. If it's not, there's something wrong. Does jit.qt.movie direct to window work? If this works, then the get_window_ptr method also works as this is qhat qt.move is using to perform its DTW trickery. If it still doesn't work, post a patch and steps to reproduce and I'll take a look.
      wes
      2008/10/18 Thijs Koerselman : > > On Sat, Oct 18, 2008 at 11:02 PM, Wesley Smith > wrote: >> >> > I've tried 2 different window handles. One from a named jit.window: >> > jit_object_method(window, gensym("get_window_ptr"), &hWnd_); >> >> This should give you the HWND of the jit.window object. I don't have >> the docs in front of me, but perhaps you could check to see if that >> returned value is in fact a valid HWND before using it. If it's not, >> something's amiss. >> > Hi Wes, I'm not sure what is the best way to test that. Like I said if I get > the classname of the HWND, it appears to be noise for the HWND returned by > get_window_ptr. The one from main_get_client() gives me "MDIClient". > > I just tried the GetWindowThreadProcessId(), and again on the main client > this returns a valid number, on the jit.window HWND this returns 0. > > So I guess you are right about the HWND not being a valid window handle. > > If there is an easy workaround by creating a dummy window from my external > directly, that would be ok for now too. I don't need to display anything in > the window since the input device is to be used only by visually impaired > people for now. > > If there's anything else I can test or if you want me to send you the code > let me know. > > Best, > Thijs > >
    • Oct 22 2008 | 2:05 pm
    • Oct 22 2008 | 6:46 pm
      On Wed, Oct 22, 2008 at 7:21 PM, Wesley Smith wrote:
      > Before I jump into this, can you at least tell me if direct to window > works? > > I did tell you, or there must be some misunderstanding on my part. It's in the first paragraph of my last post here and also the one I send directly to you (incl. the source).
      So if you are asking if direct to window works on jit.qt.movie with jit.window, the answer is yes. But then again I'm using Max 4 and it has always worked, no? I'll try max5 if that's of any help. I'm working on an old windows machine atm on which I never installed max5.
      Thijs
    • Oct 22 2008 | 7:04 pm
      Sorry, didn't see that. I was still making my way through my morning coffee when I read your last msg. wes
      2008/10/22 Thijs Koerselman : > On Wed, Oct 22, 2008 at 7:21 PM, Wesley Smith wrote: >> >> Before I jump into this, can you at least tell me if direct to window >> works? >> > > I did tell you, or there must be some misunderstanding on my part. It's in > the first paragraph of my last post here and also the one I send directly to > you (incl. the source). > > So if you are asking if direct to window works on jit.qt.movie with > jit.window, the answer is yes. But then again I'm using Max 4 and it has > always worked, no? I'll try max5 if that's of any help. I'm working on an > old windows machine atm on which I never installed max5. > > Thijs > > > > > >
    • Oct 24 2008 | 12:03 pm
      On Wed, Oct 22, 2008 at 9:04 PM, Wesley Smith wrote:
      > Sorry, didn't see that. I was still making my way through my morning > coffee when I read your last msg. > wes >
      No worries. Thanks for taking a look. Do you think there is still hope, or should I start with plan B?
      Thijs
    • Oct 26 2008 | 10:48 pm
      On Fri, Oct 24, 2008 at 2:03 PM, Thijs Koerselman > wrote:
      > On Wed, Oct 22, 2008 at 9:04 PM, Wesley Smith wrote: > >> Sorry, didn't see that. I was still making my way through my morning >> coffee when I read your last msg. >> wes >> > > > No worries. Thanks for taking a look. Do you think there is still hope, or > should I start with plan B? > >
      Hallelujah!
      HWND client = main_get_client(); HWND frame = GetParent(client);
      The handle returned by GetParent() has the classname "MaxMainWndClass" and is compatible with the DirectInput stuff, unlike its MDI sibling. The call to SetCooperativeLevel() now succeeds and all is well.
      I'm still mystified about the handle returned by jit.window. I've tried using GetParent() on it as well, but that just led to more memory corruption afaict.
      Thijs