1, most of the basic data types in C # are the same as the basic data types of C + +, so the conversion of the basic data type is relatively simple, the need to pay attention to is the size of bytes. 2. Array conversions for C + + arrays and C # you need to be aware that you need to add declarations such as [MarshalAs (UnmanagedType.ByValArray, SizeConst = 10)] To define an array of 10 elements in C + +. 3, C + + callback function interface needs to adopt the C # Delegate function method, C + + in the callback function settings, the general use of the address value, so you need to display in C # using managed functions. 4, C + + pointer array, can be used in C # IntPtr, if only the address pointer, C # in the reference type. Type pre-plus ref
Example description: Using System; Using System.Collections.Generic; Using System.Text; Using System.Runtime.InteropServices;
Namespace Ipnbsvtd_csharp {public delegate void Statuscallback (IntPtr dwinstance, IntPtr WParam, IntPtr lParam); elegate void Voicecallback (IntPtr dwinstance, byte Ucdeviceindex, IntPtr pindatabuf, ref int Pindatalen, INTPTR Poutdatabu F, int noutdatalen);
Public enum vt_message{Vt_message_set_device_info, Vt_message_update_device_info, vt_message_update_mixer_in_ctr L, Vt_message_update_mixer_out_ctrl, Vt_message_missed_calls,//Missed Call};p ublic enum Vt_task_type//terminal {vt_task_type_null,//Idle (no Task) vt_task_type_to_monitor,//Initiate monitoring vt_task_type_by_monitor, Being monitored vt_task_type_to_broadcast,//initiating the vt_task_type_by_broadcast,//receiving the mining Vt_task_type_to_talk ,//Initiate intercom Vt_task_type_by_talk,//Receive intercom Vt_task_type_multitalk,//Multiparty calls Vt_task_typ E_offlinetalk,//offline Talkback};p ublic enum vt_task_state//terminal task status {vt_task_state_null,//No task V T_task_state_stop,//Monitor stop, talkback stop, broadcast stop vt_task_state_connecting,//monitor: Connect in vt_task_state_calling ,//intercom: Call in Vt_task_state_begin_bc_prompt,//broadcast: Start tone vt_task_state_end_bc_prompt,//broadcast: End beep Vt_task_state_ongoing, Listening, intercom, broadcast};p ublic enum vt_target_state//target state {vt_target_state_null = 0,//unknown vt_target_ State_offline,//target offline vt_target_state_stop,//target stop Vt_target_state_reject, Target reject Vt_target_state_busy,//target call Busy}; [StructLayout (layoutkind.sequential)]public struct vt_task_target{public int ncount; Listener, Intercom, broadcast selected target number public int neditpos; The location currently being edited public Vt_task_type Xetasktype; Task type public vt_task_state xetaskstate; Task Group task status public Vt_target_state xetargetstate; To speak target state public bool Bisbegin; Whether the task has started (call ...) [MarshalAs (UnmanagedType.ByValArray, SizeConst = 6)] public vt_task_state[] pxeterstate; Task status for each terminal Vt_device_max_count 6 [MarshalAs (UnmanagedType.ByValArray, SizeConst = +)] public ushort[] pwid; Terminal ID (Terminal No. 0:1 ...) or section code (1: partition 1 ...) Vt_broadcast_max_count [MarshalAs (UnmanagedType.ByValArray, SizeConst = +)] public int[] PISERIDX; Server number corresponding to each terminal [MarshalAs (UnmanagedType.ByValArray, SizeConst = 6)] public byte[] Pucpanelno; NAS-8521, call to Panel, terminal corresponding panel serial number [MarshalAs (unmanagedtype.byvalarray, SizeConst = n)] public char[] strFileName; File broadcast, the file name of the current broadcast is public uint Offlinetargetip; Offline Destination IP public ushort offlinetargetport; Offline Destination port}; [StructLayout (layoutkind.sequential)]public struct tagserver{public uint ipserver; Server IP (byte reverse order) public ushort Wserverport; Server receive port (byte reverse order) public bool Bfixport; Whether to secure the receive port public ushort Whostport; Native Receive port (byte reverse order) public bool bonline; Whether online public bool bispcm; Whether it is PCM/ADPCM compressed public bool bis8k; Whether it is 8k/22k sampling public bool bismulticast; Whether it is multicast/unicast public bool Brecord; Whether to record public uint Iprecord; Recording IP public ushort wrecordport; Recording Port}; [StructLayout (layoutkind.sequential)]public struct vt_device_info{public ushort Wdeviceid; Device number (starting from 0, display to add 1) public uint iphost; Host IP (byte reverse order) public bool Bisregister; Whether to register public ushort Dwvol; Current output volume public int iservercount; Number of servers [MarshalAs (UnmanagedType.ByValArray, SizeConst = ten)] public tagserver[] pxsserver; Server public int ntaskcount; Number of tasks public int ncurtask; Current task (corresponding to subscript for xstasktarget) [MarshalAs (UnmanagedType.ByValArray, SizeConst = 1)] public vt_task_target[] Pxstaskarra Y Task target};///<summary>///cross-platform invoke method//</summary>public class nativemethod{//<summary>//path Maximum size </summary> Public const int MAX_PATH = 260; [DllImport ("IPNBSVTD.dll ")] public static extern void Ipnbsvtd_deletedevice (); [DllImport ("IPNBSVTD.dll")] public static extern byte Ipnbsvtd_createdevice (byte uccount); [DllImport ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_devicemute (ref bool Pbmute, BOOL bisaudioout, BOOL Bisse T); [DllImport ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_devicevolume (ref int Pdwvolume, BOOL bisaudioout, BOOL B IsSet); [DllImport ("IPNBSVTD.dll")] public static extern void Ipnbsvtd_setinifilepath (Byte ucdeviceindex, string Pinifilepath) ; [DllImport ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_openserver (byte Ucdeviceindex, IntPtr Hparentwnd, uint n MSG); [DllImport ("IPNBSVTD.dll")]//public static extern bool Ipnbsvtd_setbcfromfile (byte ucdeviceindex, bool Bbcfromfile, BOOL bloop,//[MarshalAs (UnmanagedType.LPArray)]string[] pstrfile, short sfilecount); [DllImport ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_setbcfromfileex (byte UcdeviceindeX, bool Bbcfromfile, bool bloop, string strfile, bool badd); public static void Setbcfromfile (byte ucdeviceindex, bool Bbcfromfile, bool bloop, list<string> files, short Sfileco UNT) {for (int i = 0; i < files. Count; i++) Ipnbsvtd_setbcfromfileex (Ucdeviceindex, Bbcfromfile, Bloop, Files[i], (i = = 0)? false:true); } [DllImport ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_setbctoterm (byte ucdeviceindex); [DllImport ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_getcurtasktarget (byte Ucdeviceindex, ref vt_task_target ptasktarget, int itaskpos); [DllImport ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_setcurtasktarget (byte Ucdeviceindex, ref vt_task_target ptasktarget, int itaskpos); [DllImport ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_taskbegin (byte ucdeviceindex, int itaskpos); [DllImport ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_taskend (byte ucdeviceindex, int itaskpos); [DllimpORT ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_getdeviceinfo (byte Ucdeviceindex, ref Vt_device_info Pdeviceinf O); [DllImport ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_getbcfilecurrent (byte ucdeviceindex, StringBuilder strf ILE); [DllImport ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_setstatuscallback (byte Ucdeviceindex, Statuscallback DW CallBack, IntPtr dwinstance); [DllImport ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_setvoicecallback (byte ucdeviceindex, Voicecallback DWCA Llback, IntPtr dwinstance); [DllImport ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_setfilebcnext (byte ucdeviceindex); [DllImport ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_setfilebcpause (byte ucdeviceindex, bool bpause); [DllImport ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_setfilebcprevious (byte ucdeviceindex); [DllImport ("IPNBSVTD.dll")] public static extern uint Ipnbsvtd_getbcfilecurrentplaypos (byte UCDeviceindex, ref uint Pbcfilelen); [DllImport ("IPNBSVTD.dll")] public static extern bool Ipnbsvtd_setfilebcplaylistpos (byte Ucdeviceindex, byte Ucplaylis TPos);}
}