如何使用DLL导入和C#事件获取回调方法C ++

问题描述 投票:0回答:1

我使用具有回调方法功能的dll:

int result = SetCallEventCalback(uint hServer, uint CallbackParam,CallEventCallback* OnCallEvent, bool SearchPhonebook)

void CallEventCallback(uint hServer, uint CallbackParam, char* CallId, int
ChannelNumber, int EventType, wchar* Param, wchar* ExtraParam)

和我为使用dll函数编写此类并获取事件但不能正常工作。我的问题是什么?

谢谢。

public class Recording
{    
    public delegate int CallBackDel(uint hServer, uint CallbackParam, string CallId, int ChannelNumber, int EventType, string Param, string ExtraParam);

    public Recording.CallBackDel CallBackdelegate = new CallBackDel(Recording.CallbackFunc);

    public string CallidP = "";

    public uint hServer = 0;

    public uint hServerP=0;

    public uint CallbackParamP = 0;

    public string CallIdP="";

    public int ChannelNumberP=0;

    public int EventTypeP=0;

    public int ConnectionStatus = 0;

    public int connect = 0;

    public string ParamP="";

    public string ExtraParamP="";

    public Recording(string Serverip, int type, string user, string password)

    {

        hServer = CreateServerHandle(Serverip, type);
        if (hServer > 0)
        {
            int connect = Recording.Connect(hServer);
            if (connect == 1)
            {
                Thread.Sleep(2000);
                ConnectionStatus = Recording.SignIn(hServer, user, password);
            }
            if (ConnectionStatus == 1)
            {
                //CallBackdelegate(hServer, CallbackParamP, CallIdP, ChannelNumberP, EventTypeP, ExtraParamP);
                Recording.SetCallEventCalback(hServer, CallbackParamP, CallBackdelegate, false);
            }
            else
            {

            }
        }
    }
    public static int CallbackFunc(uint hServer, uint CallbackParam, string CallId, int ChannelNumber, int EventType, string Param, string ExtraParam)
    {
        return (int) hServer;

    }
    //1 CreateServerHandle
    [DllImport("MJ.dll")]
    public static extern uint CreateServerHandle(string ServerName, int ServerType);        
    //2 DestroyServerHandle
    [DllImport("MJ.dll")]
    public static extern void DestroyServerHandle(uint HNDL);
    //3 Connect
    [DllImport("MJ.dll")]
    public static extern int Connect(uint hServer);
    //4 Disconnect
    [DllImport("MJ.dll")]
    public static extern int Disconnect(uint hServer);
    //5 SignIn
    [DllImport("MJ.dll")]
    public static extern int SignIn(uint hServer, string UserName, string Password);
    //6 SignOut
    [DllImport("MJ.dll")]
    public static extern int SignOut(uint hServer);
    //7 IsConnected 
    [DllImport("MJ.dll")]
    public static extern bool IsConnected(uint hServer);
    //8 IsSignedIn
    [DllImport("MJ.dll")]
    public static extern bool IsSignedIn(uint hServer);
    //9 GetMetadata
    [DllImport("MJ.dll")]
    public static extern bool GetMetadata(uint hServer, string CallId, string Metadata);
    //10 SetConnectingFinishedEventCalback
    //public delegate int SetCallEventCalback2(uint hServer, uint CallbackParam, Delegate SetCallEventCalback2, bool SearchPhonebook);
    [DllImport("MJ.dll", CharSet = CharSet.Ansi,
    CallingConvention = CallingConvention.Cdecl)]
    public static extern int SetCallEventCalback(uint hServer, uint CallbackParam, CallBackDel SetCallEventCalback2, bool SearchPhonebook);
    //11 CallEventCallback
    //void CallEventCallback(uint hServer, uint CallbackParam, char* CallId, int ChannelNumber, int EventType, wchar* Param, wchar* ExtraParam)
    [DllImport("MJ.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    public static extern void CallEventCallback(uint hServer, uint CallbackParam, string CallId, int ChannelNumber, int EventType, string Param, string ExtraParam);

    //12   Export(uint hServer, char* DestFilePath, char* CallId, int FormatType,bool RemovePilot)
    [DllImport("MJ.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    public static extern int Export(uint hServer, string DestFilePath, string CallId, int FormatType, bool RemovePilot);

}
c# callback dllimport
1个回答
0
投票

我的问题通过添加EntryPoint =“ SetCallEventCallback”解决]]

[[DllImport(“ BSF API.dll”,CharSet = CharSet.Ansi,CallingConvention = CallingConvention.Cdecl,EntryPoint =“ SetCallEventCallback”)]]公共静态外部int SetCallEventCalback(uint hServer,uint CallbackParam,CallBackDel SetCallEventCalback2,bool SearchPhonebook);

© www.soinside.com 2019 - 2024. All rights reserved.