no sound heard while playing a MIDI file in C#.Net

前端 未结 2 1758
囚心锁ツ
囚心锁ツ 2021-01-14 17:25

I use this code to play a MIDI file for my game, but I can not hear any sound from my speakers. Would you help me? It\'s kind of an emergency, please... My speakers are turn

2条回答
  •  借酒劲吻你
    2021-01-14 17:57

    I used to use the definition...

    [DllImport("winmm.dll", EntryPoint = "mciSendStringA")] 
    
    public static extern void mciSendStringA(string lpstrCommand, string lpstrReturnString, long uReturnLength, long hwndCallback); 
    

    ...in .Net 3.5 but in .Net 4.0 is gave me and unbalanced pinvoke exception! I fixed it by using this instead...

    [DllImport("winmm.dll", EntryPoint = "mciSendStringA")]
    
    public static extern void mciSendStringA(string lpstrCommand, string lpstrReturnString, int uReturnLength, IntPtr hwndCallback); 
    

    ...and passing in IntPtr.Zero as the last param.

    The only difference is the uReturnLength is an int (and not a long) and hwndCallback is a IntPtr (and not a long).

    Hope this helps...

提交回复
热议问题