title: Unable to access Handler in VB.net
body: <p>Hi I am trying to change my cursor with the custom one where i got to know from here "www.codeguru.com/columns/vb/creating-a-.net-component-with-visual-basic.htm"</p>
  
  <p>Its is throwing me an error <b>System.AccessVoilation.Exception</b> i basically understood by googling the exception but i don't know how to fix it.</p>
  
  <p>So can any one help me...</p>
  
  <p>below is my code and im getting the exception in the particular line in the program <b>lHandle = LoadCursor(0, curCursor.Handle)</b></p>
  
  <pre><code>Imports System.IO
  Imports System.Windows.Forms
  Imports System.ComponentModel.Design
  Imports System.Runtime.InteropServices
  
  Public Class AnimatedCursor_Ex
      Inherits SystemException
  
  
  Private Declare Unicode Function LoadCursorFromFile Lib "user32.dll" Alias "LoadCursorFromFileW" (ByVal filename As String) As IntPtr
  &lt;DllImport("user32", EntryPoint:="SetCursor", CharSet:=CharSet.Auto)&gt;
  Private Shared Function SetCursor(ByVal hCursor As Integer) As Integer
  End Function
  
  &lt;DllImport("user32.dll", CharSet:=CharSet.Auto)&gt;
  Public Shared Function LoadCursor(
      ByVal hInstance As IntPtr,
      ByVal lpCursorName As Integer) As IntPtr
  End Function
  
  Private Shared curCursor As Cursor
  
  Private Shared FileName As String
  
  
  
  Public Shared Sub ShowCursor()
  
      Dim lHandle As String
  
      FileName = Path.Combine(Application.StartupPath, "dinosaur.ani")
  
      curCursor = CreateCursor(FileName)
  
      lHandle = LoadCursor(0, curCursor.Handle)
  
  
  
      SetCursor(lHandle)
  
  End Sub
  
  Private Shared Function CreateCursor(ByVal filename As String) As Cursor
      Dim hCursor As IntPtr
      Dim result As Cursor = Nothing
  
      Try
          hCursor = LoadCursorFromFile(filename)
          If Not IntPtr.Zero.Equals(hCursor) Then
              result = New Cursor(hCursor)
          Else
              'could not create cursor
              Throw New ApplicationException("Could not create cursor from file " &amp; filename)
          End If
      Catch ex As Exception
          'log exception
      End Try
  
          Return result
      End Function
  End Class
  </code></pre>