locked
Play .wav in Common Intermediate Language RRS feed

  • Question

  • Now I posted something similat to this before, but now I'm more educated on the topic and have gotten somewhere. Right now I have

    .assembly extern mscorlib
    {
      .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
      .ver 2:0:0:0
    }
    .assembly extern system
    {
      .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
      .ver 2:0:0:0
    }
    .assembly Jake
    {
      .ver 2:0:0:0
    }
    .module test.exe
    .imagebase 0x00400000
    .file alignment 0x00001000
    .stackreserve 0x00100000
    .subsystem 0x0003
    .corflags 0x00000009
    .method public static void JakeInc() cil managed
    {
    .entrypoint
    ldstr "C:\Users\Jake\Desktop\sound.wav"
    call instance void [system]System.Media.SoundPlayer::.ctor(string)
    ret
    }
    
    It complies fine, but when I run it I get Unhandled Exception: System.InvalidProgramException: Common Language Runtime detected an invalid program.
      at JakeInc()
    When I used PEVerify, I got <Module>::JakeInc][offset 0x00000005] Stack underflow. I know what this but I'm not sure why I'm getting this error.
    Monday, February 4, 2013 2:26 AM

Answers

  • Hi Jake,

    Welcome to the MSDN Forum.

    When you need to call the .ctor, please use the newobj operator: http://msdn.microsoft.com/en-us/library/system.reflection.emit.opcodes.newobj.aspx 

    And there is the whole success code:

    .assembly extern mscorlib
    {
      .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
      .ver 2:0:0:0
    }
    .assembly extern system
    {
      .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
      .ver 2:0:0:0
    }
    .assembly Jake
    {
      .ver 2:0:0:0
    }
    .module test.exe
    .imagebase 0x00400000
    .file alignment 0x00001000
    .stackreserve 0x00100000
    .subsystem 0x0003
    .corflags 0x00000009
    .method public static void JakeInc() cil managed
    {
    .entrypoint
    ldstr "C:\\Users\\Jake\\Desktop\\sound.wav"
    newobj instance void [system]System.Media.SoundPlayer::.ctor(string)
    pop
    ret
    }

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jakeinc Wednesday, February 6, 2013 11:39 PM
    • Unmarked as answer by Jakeinc Thursday, February 7, 2013 4:27 AM
    • Marked as answer by Mike Feng Friday, February 8, 2013 4:58 AM
    Tuesday, February 5, 2013 7:23 AM
  • Hi Jakeinc,

    Based on my test, I assume your application type is a console application.

    At this situation, please call the PlaySync method: http://msdn.microsoft.com/en-us/library/system.media.soundplayer.playsync.aspx 

    Because 

    The PlaySync method uses the current thread to play a .wav file, preventing the thread from handling other messages until the load is complete. 

    And The Play method plays the sound using a new thread.

    And the new thread will be terminated when the main console thread exited.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jakeinc Thursday, February 7, 2013 10:21 PM
    Thursday, February 7, 2013 10:19 AM

All replies

  • Hi Jake,

    Welcome to the MSDN Forum.

    When you need to call the .ctor, please use the newobj operator: http://msdn.microsoft.com/en-us/library/system.reflection.emit.opcodes.newobj.aspx 

    And there is the whole success code:

    .assembly extern mscorlib
    {
      .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
      .ver 2:0:0:0
    }
    .assembly extern system
    {
      .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
      .ver 2:0:0:0
    }
    .assembly Jake
    {
      .ver 2:0:0:0
    }
    .module test.exe
    .imagebase 0x00400000
    .file alignment 0x00001000
    .stackreserve 0x00100000
    .subsystem 0x0003
    .corflags 0x00000009
    .method public static void JakeInc() cil managed
    {
    .entrypoint
    ldstr "C:\\Users\\Jake\\Desktop\\sound.wav"
    newobj instance void [system]System.Media.SoundPlayer::.ctor(string)
    pop
    ret
    }

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jakeinc Wednesday, February 6, 2013 11:39 PM
    • Unmarked as answer by Jakeinc Thursday, February 7, 2013 4:27 AM
    • Marked as answer by Mike Feng Friday, February 8, 2013 4:58 AM
    Tuesday, February 5, 2013 7:23 AM
  • OK thanks part I down I guess but It still doesn't play the sound Its now

    .assembly extern mscorlib
    {
      .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
      .ver 2:0:0:0
    }
    .assembly extern system
    {
      .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
      .ver 2:0:0:0
    }
    .assembly Jake
    {
      .ver 2:0:0:0
    }
    .module test.exe
    .imagebase 0x00400000
    .file alignment 0x00001000
    .stackreserve 0x00100000
    .subsystem 0x0003
    .corflags 0x00000009
    .method public static void JakeInc() cil managed
    {
    .entrypoint
    ldstr "C:\\Users\\Jake\\Desktop\\sound.wav"
    newobj instance void [system]System.Media.SoundPlayer::.ctor(string)
    call instance void [system]System.Media.SoundPlayer::Play()
    ret
    }

    thank you for your cooperation there are almost no online resources besides msdn to help me
    Thursday, February 7, 2013 4:29 AM
  • Hi Jakeinc,

    Based on my test, I assume your application type is a console application.

    At this situation, please call the PlaySync method: http://msdn.microsoft.com/en-us/library/system.media.soundplayer.playsync.aspx 

    Because 

    The PlaySync method uses the current thread to play a .wav file, preventing the thread from handling other messages until the load is complete. 

    And The Play method plays the sound using a new thread.

    And the new thread will be terminated when the main console thread exited.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jakeinc Thursday, February 7, 2013 10:21 PM
    Thursday, February 7, 2013 10:19 AM