3
这是从MIDI点网http://code.google.com/p/midi-dot-net/库:为什么这个C#代码不是类型安全的,为什么这个其他位使它类型安全?
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);
...
/// <summary>
/// Opens a MIDI output device.
/// </summary>
/// 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);
}
请问这个最后的功能使Win32调用类型安全的?
我不认为它是类型安全的,但它是更安全,因为' MidiOpenFlags'只有正确的值。 –