Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / August 2008



Tip: Looking for answers? Try searching our database.

JoySetCapture fails the second time in the same process

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dean Earley - 21 Aug 2008 09:28 GMT
Hi all.

I have spent the last few days playing with the winMM Joystick library
and have come across a fairly major problem with joySetCapture().

When I call this for the first time it works correctly and I get the
notifications until I call joyReleaseCapture().

If I then start capturing it again, it fails with error code 6
(MMSYSERR_NODRIVER) until I restart the process.
While it has "broken", other process can capture it fine (once).

The code in question that starts it is:

  If joySetCapture(CaptureForm.hWnd, IntIndex, 100, -1) = 0 Then

The interval and changed parameters don't have any effect on the result.

I have confirmed this on Windows XP (SP2 and SP3), and Vista (SP1).
Windows 2K (SP4) works as expected.

This post is more to inform other people as I have now moved over to
using DirectInput, but if anyone has any ideas or suggestions, I'll
happily test them.

Signature

Dean Earley (dean.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

Thorsten Albers - 21 Aug 2008 12:47 GMT
Dean Earley <dean.earley@icode.co.uk> schrieb im Beitrag
<OaIhuf2AJHA.760@TK2MSFTNGP05.phx.gbl>...
>    If joySetCapture(CaptureForm.hWnd, IntIndex, 100, -1) = 0 Then

- In C/C++ TRUE is not -1 but 1
- Did you ensure that joyReleaseCapture() is called with the same ID as
youSetCapture()?

Signature

----------------------------------------------------------------------
Thorsten Albers                               albers(a)uni-freiburg.de
----------------------------------------------------------------------

Dean Earley - 21 Aug 2008 13:22 GMT
> Dean Earley <dean.earley@icode.co.uk> schrieb im Beitrag
> <OaIhuf2AJHA.760@TK2MSFTNGP05.phx.gbl>...
>>    If joySetCapture(CaptureForm.hWnd, IntIndex, 100, -1) = 0 Then
>
> - In C/C++ TRUE is not -1 but 1

It treated -1 as "non zero" and so, true, but it made no difference to
the failure either way.

> - Did you ensure that joyReleaseCapture() is called with the same ID as
> youSetCapture()?

Yes.
It did stop sending the notifications.

Signature

Dean Earley (dean.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

Thorsten Albers - 21 Aug 2008 16:21 GMT
Dean Earley <dean.earley@icode.co.uk> schrieb im Beitrag
<egwSgi4AJHA.272@TK2MSFTNGP04.phx.gbl>...
> It treated -1 as "non zero" and so, true, but it made no difference to
> the failure either way.

The MSDN documentation is a bit unclear on this point: It says that if TRUE
is passed then ...; otherwise, i.e. with all other values ...
It depends on who the check of the value is implemented in the C code: If
it checks with
 if (fChanged == TRUE)
'-1' (FFFFFFFFh) would be treated as FALSE; if it checks with
 if (fChanged)
'-1' would be treated as TRUE

> > - Did you ensure that joyReleaseCapture() is called with the same ID as
> > youSetCapture()?
> Yes.
> It did stop sending the notifications.

So we need more code to find the problem (including the declarations of
joySetCapture() and joyReleaseCapture()).

Signature

----------------------------------------------------------------------
Thorsten Albers                               albers(a)uni-freiburg.de
----------------------------------------------------------------------

Dean Earley - 21 Aug 2008 17:25 GMT
> Dean Earley <dean.earley@icode.co.uk> schrieb im Beitrag
> <egwSgi4AJHA.272@TK2MSFTNGP04.phx.gbl>...
[quoted text clipped - 5 lines]
> So we need more code to find the problem (including the declarations of
> joySetCapture() and joyReleaseCapture()).

Declarations:
Private Declare Function joySetCapture Lib "winmm.dll" (ByVal hWnd As
Long, ByVal uJoyID As Long, ByVal uPeriod As Long, ByVal fChanged As
Long) As Long
Private Declare Function joyReleaseCapture Lib "winmm.dll" (ByVal uJoyID
As Long) As Long

'Capture the joystick
If joySetCapture(CaptureForm.hWnd, IntIndex, 100, -1) = 0 Then
  Captured = True
End If

Private Function SubClassed_WindowProc(ByVal hWnd As Long, ByVal Msg As
Long, ByVal wParam As Long, ByVal lParam As Long, Handled As Boolean) As
Long
  Select Case Msg
  Case MM_JOY1MOVE, MM_JOY1ZMOVE, MM_JOY1BUTTONDOWN, MM_JOY1BUTTONUP,
MM_JOY2MOVE, MM_JOY2ZMOVE, MM_JOY2BUTTONDOWN, MM_JOY2BUTTONUP
    RaiseEvent JoystickEvent(Msg, wParam, lParam)
    Handled = True
  End Select
End Function

'Release the capture
If Captured Then
  joyReleaseCapture IntIndex
  Captured = False
End If

IntIndex is 0 for the first device, and ReleaseCapture() returns 0 every
time.

All my code did on reception of the event was beep which it does
profusely the first time I capture it, but never on subsequent attempts.

There is no other code involved in the capture, and I'm not the only
person to have seen this (although I can't find the post now)

The results are the same regardless of the interval, changed flag or the
threshold so they are not the problem.

Signature

Dean Earley (dean.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

Thorsten Albers - 21 Aug 2008 20:16 GMT
Dean Earley <dean.earley@icode.co.uk> schrieb im Beitrag
<ut4UJq6AJHA.908@TK2MSFTNGP03.phx.gbl>...
> Private Function SubClassed_WindowProc(ByVal hWnd As Long, ByVal Msg As
> Long, ByVal wParam As Long, ByVal lParam As Long, Handled As Boolean) As
[quoted text clipped - 6 lines]
>    End Select
> End Function

- Do you pass the messages after your own processing to the default window
procedure?
- At which point do you remove the subclassing of the window: before or
after joyReleaseCapture() is called?

Signature

----------------------------------------------------------------------
Thorsten Albers                               albers(a)uni-freiburg.de
----------------------------------------------------------------------

Dean Earley - 22 Aug 2008 08:48 GMT
> Dean Earley <dean.earley@icode.co.uk> schrieb im Beitrag
> <ut4UJq6AJHA.908@TK2MSFTNGP03.phx.gbl>...
[quoted text clipped - 11 lines]
> - Do you pass the messages after your own processing to the default window
> procedure?

No as I have "handled" them.
There is nothing in MSDN that says it requires any given return value or
 passing up the chain.

> - At which point do you remove the subclassing of the window: before or
> after joyReleaseCapture() is called?

After releasing capture, normally when that window is closed.

Can anyone confirm that the process I have described actually works on
their PC rather then us chasing a real problem in windows?

Signature

Dean Earley (dean.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

Dean Earley - 26 Aug 2008 17:29 GMT
>> Dean Earley <dean.earley@icode.co.uk> schrieb im Beitrag
>> <ut4UJq6AJHA.908@TK2MSFTNGP03.phx.gbl>...
[quoted text clipped - 25 lines]
> Can anyone confirm that the process I have described actually works on
> their PC rather then us chasing a real problem in windows?

As no one else can get this to work (or hasn't seen/tried) I can only
assume it is a bug in the Joystick API.

Oh well, good luck anyone else that tries it.

Signature

Dean Earley (dean.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.