Recording voice using winmm.dll RRS feed

  • Question

  • Hi,

    I have a created a small application that records and save audio. However, my application needs to save the wave file to the sever computer. 

    I used my code in my asp.net application ,It is working fine in local machine.

    But if I publish it on server, It does not save the recording on server machine. But it create wav file with zero length.

    Please can some one help me with this problem??

    I am using VS2017 Web form application.

    My code : 

    public class AudioHandler 

            [DllImport("winmm.dll", CharSet = CharSet.Auto)]
            private static extern uint mciSendString([MarshalAs(UnmanagedType.LPTStr)] string command,
                                                    StringBuilder returnValue,
                                                    int returnLength,
                                                    IntPtr winHandle);

            public AudioHandler()
                mciSendString("Open new Type waveaudio alias rec", null, 0, IntPtr.Zero);
            public void Record()
                mciSendString("Record rec", null, 0, IntPtr.Zero);

            public void Save(string path)
                uint result = 0;
                result = mciSendString("save rec "+ path , null, 0, IntPtr.Zero);

            public void Dispose()
                mciSendString("close rec", null, 0, IntPtr.Zero);

    Tuesday, May 21, 2019 4:03 PM

All replies

  • Many server-class machines do not have audio devices at all.

    What good would it do to record what's happening in the server room anyway?

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Tuesday, May 21, 2019 6:07 PM
  • HI ,

    My problem is every thing was working fine, audio file also creating but content is missing. 


    Same issue 

    Wednesday, May 22, 2019 2:49 AM
  • Hi Yasintha Srimanthi,

    Thank you for posting here.

    Since your question is more related to Web form, you could post a new thread in ASP.NET forum for suitable support.


    The C# forum is for C# related question, we discuss and ask the C# programming language, IDE, libraries, samples and tools here. Thank you for your understanding.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 22, 2019 9:07 AM
  • HI,

    I am not sure it is a web form issue, because it work fine on my local machine. but bot in server. Can it be a dll issue. 

    Thursday, May 23, 2019 4:13 AM
  • I don't know what you mean by "same issue".  My comment still applies.  When you run your code on a server, it is going to try to access the microphone ON THE SERVER.  If your server doesn't have a microphone, and many servers do not, then you will not be able to record any data.

    You do understand that an application running on a server does not have access to the microphone on your local computer, right?

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Thursday, May 23, 2019 7:10 AM