2 yulianshui yulianshui 于 2014.03.05 18:09 提问

c#调用pjsip 的 c++ dll 没有参数正常,但是有参数的时候就报错

pjsip 的 c++ dll ,按照文档里面的参数设置来传递参数,但是,在按照P/invoke 方式进行获取,但是运行的结果是,没有参数的都能正常运行,有参数的却报错,错误是这样的

对 PInvoke 函数“dllTest!dllTest.Program::dll_makeCall”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。

代码如下
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace dllTest
{
class Program
{
///
/// 初始化
///
///
[DllImport("pjsipDll.dll", CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int dll_init();
///
/// 主函数
///
///
[DllImport("pjsipDll.dll", CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int dll_main();

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    [DllImport("pjsipDll.dll", CharSet = CharSet.Ansi, SetLastError = true)]
    private static extern int dll_getNumOfCodecs();
    /// <summary>
    /// 打电话
    /// </summary>
    /// <param name="accountId">用户名</param>
    /// <param name="uri">地址</param>
    /// <returns></returns>
    [DllImport("pjsipDll.dll", EntryPoint = "dll_makeCall")]
    private static extern int dll_makeCall(int accountId, string uri);
    /// <summary>
    /// 回电话
    /// </summary>
    /// <param name="callId"></param>
    /// <param name="code"></param>
    /// <returns></returns>
    [DllImport("pjsipDll.dll", CharSet = CharSet.Ansi, SetLastError = true)]
    private static extern int dll_answerCall(int callId, int code);
    /// <summary>
    /// 
    /// </summary>
    /// <param name="callId"></param>
    /// <returns></returns>
    [DllImport("pjsipDll.dll", EntryPoint = "dll_releaseCall", CharSet = CharSet.Ansi, SetLastError = true)]
    private static extern int dll_releaseCall(int callId);

    static void Main(string[] args)
    {
        try
        {          
            dll_init();
            dll_main();
            string uri = "sip:bob@192.168.91.128:5060";
            int sessionID = dll_makeCall(0, uri);
            Console.WriteLine(sessionID > 0 ? "成功" : "失败" + "----->SessionID:" + sessionID);
            Console.ReadLine();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
            return;
        }

    }
}

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!