title: Why is this C# code not type-safe and why does this other bit make it type-safe?
body: <p>This is from the midi-dot-net <a href="http://code.google.com/p/midi-dot-net/" rel="nofollow">http://code.google.com/p/midi-dot-net/</a> library:</p>
  
  <pre><code>static class Win32API
  { ...
  
      #region Non-Typesafe Bindings
  
       // The bindings in this section are not typesafe, so we make them private
       // and provide typesafe variants    
       [DllImport("winmm.dll", SetLastError = true)]
       private static extern MMRESULT midiOutOpen(out HMIDIOUT lphmo, 
          UIntPtr uDeviceID, MidiOutProc dwCallback, UIntPtr dwCallbackInstance, 
          MidiOpenFlags dwFlags);
  
       ...
  
       /// &lt;summary&gt;
       /// Opens a MIDI output device.
       /// &lt;/summary&gt;
       /// NOTE: This is adapted from the original Win32 function in order
       ///       to make it typesafe.
       ///
       /// Win32 docs: http://msdn.microsoft.com/en-us/library/ms711632(VS.85).aspx
       public static MMRESULT midiOutOpen(out HMIDIOUT lphmo,
          UIntPtr uDeviceID, MidiOutProc dwCallback, UIntPtr dwCallbackInstance)
       {
          return midiOutOpen(out lphmo, uDeviceID, dwCallback, dwCallbackInstance,
                    dwCallback == null ? MidiOpenFlags.CALLBACK_NULL :
                       MidiOpenFlags.CALLBACK_FUNCTION);
       }
  </code></pre>
  
  <p>How does this last function make the win32 call type-safe?</p>