< Previous by Date Date Index Next by Date >
  Thread Index Next in Thread >

[sipxtapi-dev] c# PInvoke of sipxMedia SipxAudioGetOutputDevice


Hi,

 

I am having problems with my c# wrapper for sipxtapi that is based on the VB one on the SIPfoundary site.  My code is producing the following exception “Attempted to read or write protected memory. This is often an indication that other memory is corrupt.” This happens when I call the sipxAudioGetOutputDevice via the following DLLImport statement and it is the last argument that is causing the problem. 

 

[DllImport(SipxConfig.SIPXTAPI_DLL, SetLastError = true, CallingConvention = CallingConvention.Cdecl, EntryPoint = "sipxAudioGetOutputDevice")]

protected static extern SipxResult SipxAudioGetOutputDevice(IntPtr instanceHandle, int deviceNumber,  ref String deviceName);

 

If I remove the ref modifier and it doesn’t crash but I get rubish back.  I have tried String and string types as well as StringBuilder and also the out modifier instead of the ref but nothing has worked.

 

It was working fine and the problem seems to have started with my installation of Vista SP1.  I originally googled and found people haveing problems with DEP (Data Execution Prevention) but turned this off without effect.

 

I am using Visual studio 2005 and a recent (2 days ago) checkout of sipxtapi.  Sipxtapi itself compiles and I can run the example placecall.exe sucessfully which makes me think it is the way I am using PInvoke.  I am calling SipxAudioGetNumInputDevices a few lines earlier and that works OK so it isn’t something fundamental with calling sipxtapi but specific to this bit of code.

 

Apparently some of the .net CLR stuff has tightened up of pointer handling in the latest service pack (not that I know what that means) so this may have been wrong before and is only now showing up.

 

Has anyone any ideas what else I can try?

 

Code below

 

Cheers

 

Joe

 

public System.Collections.Generic.List<string> GetDevices(SipxMediaDeviceType type)

        {

            System.Collections.Generic.List<string> rv = new System.Collections.Generic.List<string>();

            // Display the list of input devices

            int NumberOfDevices = 0;

            String DeviceName = “”;

            SipxResult MySipxResult;

 

            if (type == SipxMediaDeviceType.Input)

            {

                MySipxResult = SipxAudioGetNumInputDevices(m_Instance.InstanceHandle, ref NumberOfDevices);

            }

            else

            {

                MySipxResult = SipxAudioGetNumOutputDevices(m_Instance.InstanceHandle, ref NumberOfDevices);

            }

            if (MySipxResult != SipxResult.Success)

            {

                throw new SipxException(MySipxResult);

            }

            else

            {

                for (int i = 0; i <= NumberOfDevices - 1; i++)

                {

                    if (type == SipxMediaDeviceType.Input)

                    {

                        MySipxResult = SipxAudioGetInputDevice(m_Instance.InstanceHandle, i, ref DeviceName);

                    }

                    else

                    {

                       MySipxResult = SipxAudioGetOutputDevice(m_Instance.InstanceHandle, i,ref DeviceName); //This line fails!

                    }

                    if (MySipxResult != SipxResult.Success)

                    {

                        throw new SipxException(MySipxResult);

                    }

                    else

                    {

                        rv.Add(DeviceName.ToString());

                    }

                }

            }

            return rv;

        }