Error in Direct Input Mouse Tester

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
Fallental
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 43
Joined: Mon Mar 02, 2009 6:13 pm

Error in Direct Input Mouse Tester

Post by Fallental »

Im having an error when debugging the mouse test program that i just wrote for chapter 5
The line in the code in red below is causing this error:

LoaderLock was detected
DLL 'C:\WINDOWS\assembly\GAC\Microsoft.DirectX\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.



Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectInput


Public Class Form1

Private mouse As DirectInput.Device
Private mousestate As DirectInput.MouseState

Private WithEvents clock As Timer


Public Function Init_Mouse() As Boolean
Try
'create new mouse device
mouse = New DirectInput.Device(SystemGuid.Mouse)

'set cooperative level for mouse
Dim cooplevel As CooperativeLevelFlags = _
CooperativeLevelFlags.Background Or _
CooperativeLevelFlags.NonExclusive
mouse.SetCooperativeLevel(Me, cooplevel)

'try to acquire the mouse
mouse.Acquire()

Return True

Catch ex As Exception
Return False
End Try

End Function

Public Sub Mouse_Click(ByVal button As Integer)
TextBox4.Text = button.ToString
End Sub

Public Sub Mouse_Move(ByVal X As Integer, ByVal Y As Integer)
TextBox1.Text = X.ToString
TextBox2.Text = Y.ToString
End Sub

Public Sub Mouse_Wheel(ByVal Z As Integer)
TextBox3.Text = Z.ToString
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Not Init_Mouse() Then
MessageBox.Show("Error acquiring mouse device.")
Me.Close()
End If

'create the timer
clock = New Timer()
clock.Interval = 100
clock.Start()

End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
mouse.Unacquire()
mouse.Dispose()
mouse = Nothing
End Sub

Private Sub clock_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles clock.Tick
'poll mouse for movement and button presses
mousestate = mouse.CurrentMouseState
Dim b() As Byte = mousestate.GetMouseButtons()
If (b(0) > 0) Then Mouse_Click(1)
If (b(1) > 0) Then Mouse_Click(2)
If (b(2) > 0) Then Mouse_Click(3)

If mousestate.X <> 0 Or mousestate.Y <> 0 Then
Mouse_Move(mousestate.X, mousestate.Y)
End If
If mousestate.Z <> 0 Then
Mouse_Wheel(mousestate.Z)
End If

End Sub

End Class


Please Help! Thanks!
Fallental
Fallental
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 43
Joined: Mon Mar 02, 2009 6:13 pm

Re: Error in Direct Input Mouse Tester

Post by Fallental »

please help!?
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Error in Direct Input Mouse Tester

Post by MarauderIIC »

Hmm, I can't find any recent information relating to this, although I can find some old info that might help. If you need a "FAST ANSWER," try IRC, depending on time of day.

Anyone else?
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Post Reply