c+++関数のc氡関数の例のプログラムを回転して分かち合います。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace FDEP
{
/// <summary>
///
///
/// </summary>
public class ImportDLL
{
#region *
//*****************************************************************
//
//
//MR_PROTOCOLTYPE_MRSTANDAND 0x01 FDEP
//MR_PROTOCOLTYPE_SELFCUSTOM 0xFF
/// <summary>
///
/// </summary>
public const uint MR_PROTOCOLTYPE_MRSTANDAND = 0x01; // SBSP 。
public const uint MR_PROTOCOLTYPE_SELFCUSTOM = 0xFF; // 。
//*****************************************************************
//
//
//MR_MSGFLAG_PERSIST 0x01 , 。
//MR_MSGFLAG_COMPRESS 0x02 ,
/// <summary>
///
/// </summary>
public const uint MR_MSGFLAG_PERSIST = 0x01; // , 。
public const uint MR_MSGFLAG_COMPRESS = 0x02; // , 。
//*****************************************************************
//
//
//MR_MAXLEN_ADDR 64
//MR_MAXLEN_PKGID 64
//MR_MAXLEN_USERDATA 256
//MR_FIXLEN_EXPIREDABSTIME 20
/// <summary>
///
/// </summary>
public const int MR_MAXLEN_ADDR = 64; // 。
public const int MR_MAXLEN_PKGID = 64; // 。
public const int MR_MAXLEN_USERDATA = 256; // 。
public const int MR_FIXLEN_EXPIREDABSTIME = 20; // 。
//*****************************************************************
//
//MR_ERRCODE_OK 0
//MR_ERRCODE_PARAMERR -1
//MR_ERRCODE_CONNERR -2
//MR_ERRCODE_TIMEEXPIRED -3
//MR_ERRCODE_TIMEOUT -4
//MR_ERRCODE_NOMSG -5
//MR_ERRCODE_BUFTOOSHORT -6
//MR_ERRCODE_BUFTOOBIG -7
//MR_ERRCODE_SYSERROR -8
#endregion
#region *
/// <summary>
///
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct STUsgProperty
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MR_MAXLEN_ADDR)]
public string m_szSourceUserID;//MR_MAXLEN_ADDR , “\0”
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MR_MAXLEN_ADDR)]
public string m_szSourceAppID;//MR_MAXLEN_ADDR , “\0”
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MR_MAXLEN_ADDR)]
public string m_szDestUserID;//MR_MAXLEN_ADDR , “\0”
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MR_MAXLEN_ADDR)]
public string m_szDestAppID;//MR_MAXLEN_ADDR , “\0”
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MR_MAXLEN_PKGID)]
public string m_szPkgID;//MR_MAXLEN_PKGID , “\0” , MrCreatePkgID , ( '\0')
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MR_MAXLEN_PKGID)]
public string m_szCorrPkgID;//MR_MAXLEN_PKGID , “\0” ,
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MR_MAXLEN_USERDATA)]
public string m_szUserData1;//MR_MAXLEN_USERDATA 1, “\0” ,
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MR_MAXLEN_USERDATA)]
public string m_szUserData2;//MR_MAXLEN_USERDATA 2, “\0” ,
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MR_FIXLEN_EXPIREDABSTIME)]
public string m_szExpiredAbsTime;//MR_FIXLEN_EXPIREDABSTIME , “\0” , “YYYY-MM-DD HH:MM:SS”。 , , , 。
public byte m_ucFlag;// , 8 , : 0 -- 1 , , ;
// 1 -- 1
public byte m_ucProtocolType;// , :MR_PROTOCOLTYPE_MRSTANDAND 0x01 FDEP
//MR_PROTOCOLTYPE_SELFCUSTOM 0xFF
}
/// <summary>
///
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct STUConnInfo
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string m_szMRIP;// IP , "\0" , “xxx.xxx.xxx.xxx”
public UInt16 m_usMRPort;//
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string m_szMRIPBak;// IP ,
public UInt16 m_usMRPortBak;// , 0
}
#endregion
#region *
/// <summary>
///
/// </summary>
/// <param name="psPkg"> </param>
/// <param name="iPkgLen"> </param>
/// <param name="pMsgPropery"> </param>
/// <param name="pvUserData"> </param>
/// <returns></returns>
[UnmanagedFunctionPointerAttribute(CallingConvention.StdCall)]
public delegate int OnReceiveCallBack(string psPkg, int iPkgLen, ref STUsgProperty pMsgPropery, IntPtr pvUserData);
//typedef int (*OnReceiveCallBack)(const char* psPkg, int iPkgLen, const STUMsgProperty* pMsgPropery, void* pvUserData);
/// <summary>
/// 1. , , FDAP
/// </summary>
/// <param name="psAppID"> </param>[in]
/// <param name="psPasswd"> , </param>[in]
/// <param name="onReceive"> </param>[in]
/// <param name="oConnInfo"> </param>[in]
/// <param name="pvUserData"> </param>[in]
/// <returns>NULL NULL , , </returns>
[DllImport("mrapi.dll", EntryPoint = "MrInit", CallingConvention = CallingConvention.StdCall, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern IntPtr MrInit(string psAppID, string psPasswd, OnReceiveCallBack onReceive, STUConnInfo oConnInfo, IntPtr pvUserData);
//void* _stdcall MrInit(const char* psAppID, const char* psAppPasswd,OnReceiveCallBack onReceive,const STUConnInfo oConnInfo, void* pvUserData);
/// <summary>
/// 2. , , FDAP
/// </summary>
/// <param name="psUserCertID"> </param>[in]
/// <param name="psAppID"> </param>[in]
/// <param name="psPasswd"> , </param>[in]
/// <param name="onReceive"> </param>[in]
/// <param name="oConnInfo"> </param>[in]
/// <param name="pvUserData"> </param>[in]
/// <returns>NULL NULL , , </returns>
[DllImport("mrapi.dll", EntryPoint = "MrInit1", CallingConvention = CallingConvention.StdCall, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern IntPtr MrInit1(string psUserCertID, string psAppID, string psPasswd, OnReceiveCallBack onReceive, STUConnInfo oConnInfo, IntPtr pvUserData);
/// <summary>
/// 3. FDAP 。 FDEAPI , ,
/// </summary>
/// <param name="pHandle"> , </param>[out]
/// <param name="psUserCertID"> </param>[in]
/// <param name="psAppID"> </param>[in]
/// <param name="psPasswd"> , </param>[in]
/// <param name="pMsgProperty"> </param>[in]
/// <param name="onReceive"> </param>[in]
/// <param name="oConnInfo"> </param>[in]
/// <param name="pvUserData"> </param>[in]
/// <param name="iThreadCount"> OnReceive </param>[in]
/// <returns> </returns>
[DllImport("mrapi.dll", EntryPoint = "MrInit1Ex1", CallingConvention = CallingConvention.StdCall, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern IntPtr MrInit1Ex1(out IntPtr pHandle, string psUserCertID, string psAppID, string psPasswd, ref STUsgProperty pMsgProperty, OnReceiveCallBack onReceive, STUConnInfo oConnInfo, IntPtr pvUserData, int iThreadCount);
/// <summary>
/// 4. FDAP 。 FDEAPI , ,
/// </summary>
/// <param name="pHandle"> , </param>[out]
/// <param name="psAppID"> </param>[in]
/// <param name="psPassws"> , </param>[in]
/// <param name="pOnRecvMsgPropery"> OnReceive , , NULL</param>[in]
/// <param name="onReceive"> </param>[in]
/// <param name="pConnInfo"> </param>[in]
/// <param name="pvUserData"> </param>[in]
/// <param name="iThreadCount"> OnReceive </param>
/// <returns> </returns>
[DllImport("mrapi.dll", EntryPoint = "MrInit2", CallingConvention = CallingConvention.StdCall, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern IntPtr MrInit2(out IntPtr pHandle, string psAppID, string psPassws, ref STUsgProperty pOnRecvMsgPropery, OnReceiveCallBack onReceive, ref STUConnInfo pConnInfo, IntPtr pvUserData, int iThreadCount);
//void* _stdcall MrInit2(void** ppHandle, const char* psAppID, const char* psAppPasswd, STUMsgProperty* pOnRecvMsgPropery,OnReceiveCallBack onReceive,const STUConnInfo* pConnInfo, void* pvUserData, int iThreadCount);
/// <summary>
/// 5.
/// </summary>
/// <param name="pHandle"> , MrInit </param>
/// <returns>0 1 </returns>
[DllImport("mrapi.dll", EntryPoint = "MrIsLinkOK", CallingConvention = CallingConvention.StdCall, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern int MrIsLinkOK(IntPtr pHandle);
//int _stdcall MrIsLinkOK(void* pHandle)
/// <summary>
/// 6.
/// </summary>
/// <param name="pHandle"> , MrInit </param>[in]
/// <param name="szPkgID"> </param>[out]
/// <returns>0 </returns>
[DllImport("mrapi.dll", EntryPoint = "MrCreatePkgID", CallingConvention = CallingConvention.StdCall, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern int MrCreatePkgID(IntPtr pHandle, StringBuilder szPkgID);
//int _stdcall MrCreatePkgID(void* pHandle,char szPkgID[MR_MAXLEN_PKGID])
/// <summary>
/// 7.
/// </summary>
/// <param name="pHandle"> , MrInit </param>[in]
/// <param name="psPkg"> </param>[in]
/// <param name="iPkgLen"> </param>[in]
/// <param name="pMsgPropery"> </param>[in/out]
/// <param name="iMillSecTimeo"> </param>[in]
/// <returns>0 </returns>
[DllImport("mrapi.dll", EntryPoint = "MrSend", CallingConvention = CallingConvention.StdCall, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern int MrSend(IntPtr pHandle, string psPkg, int iPkgLen, ref STUsgProperty pMsgPropery, int iMillSecTimeo);
//int _stdcall MrSend(void* pHandle,const char* psPkg,int iPkgLen,STUsgProperty* pMsgPropery,int iMillSecTimeo);
/// <summary>
/// 8. 1
/// </summary>
/// <param name="pHandle"> , MrInit </param>[in]
/// <param name="ppsPkg"> , </param>[out]
/// <param name="piOutPkgLen"> </param>[out]
/// <param name="pMsgPropery"> </param>[in/out]
/// <param name="iMillSecTimeo"> </param>[in]
/// <returns>0 </returns>
[DllImport("mrapi.dll", EntryPoint = "MrReceive1", CallingConvention = CallingConvention.StdCall, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern int MrReceive1(IntPtr pHandle, out IntPtr ppsPkg, out int piOutPkgLen, ref STUsgProperty pMsgPropery, int iMillSecTimeo);
//int _stdcall MrReceive1(void* pHandle, char** ppsPkg, int* piOutPkgLen, STUMsgProperty* pMsgPropery, int iMillSecTimeo);
/// <summary>
/// 9.
/// </summary>
/// <param name="psPkg"> MrReceivel1 </param>[in]
/// <returns> </returns>
[DllImport("mrapi.dll", EntryPoint = "MrReceive1_FreeBuf", CallingConvention = CallingConvention.StdCall, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern IntPtr MrReceive1_FreeBuf(string psPkg);
//void _stdcall MrReceive1_FreeBuf(char* psPkg);
/// <summary>
/// 10.
/// </summary>
/// <param name="pHandle"> , MrInit </param>[in]
/// <param name="piOutPkgLen"> </param>[out]
/// <param name="pMsgPropery"> </param>[in/out]
/// <param name="iMillSecTimeo"> </param>[in]
/// <returns>0 </returns>
[DllImport("mrapi.dll", EntryPoint = "MrBrowse", CallingConvention = CallingConvention.StdCall, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern int MrBrowse(IntPtr pHandle, out int piOutPkgLen, ref STUsgProperty pMsgPropery, int iMillSecTimeo);
//int _stdcall MrBrowse(void* pHandle, int* piOutPkgLen, STUMsgProperty* pMsgPropery, int iMillSecTimeo);
/// <summary>
/// 11. 2
/// </summary>
/// <param name="pHandle"> , MrInit </param>[in]
/// <param name="ppsPkg"> , </param>[out]
/// <param name="piOutPkgLen"> </param>[out]
/// <param name="iBufLenIn"> </param>[out]
/// <param name="pMsgPropery"> </param>[in/out]
/// <param name="iMillSecTimeo"> </param>[in]
/// <returns>0 </returns>
[DllImport("mrapi.dll", EntryPoint = "MrReceive2", CallingConvention = CallingConvention.StdCall, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern int MrReceive2(IntPtr pHandle, out IntPtr ppsPkg, out int piOutPkgLen, out int iBufLenIn, ref STUsgProperty pMsgPropery, int iMillSecTimeo);
//int _stdcall MrReceive2(void* pHandle, char** ppsPkg, int* piOutPkgLen, int* iBufLenIn, STUMsgProperty* pMsgPropery, int iMillSecTimeo);
/// <summary>
/// 12. 3
/// </summary>
/// <param name="pHandle"> , MrInit </param>[in]
/// <param name="ppsPkg"> , </param>[out]
/// <param name="piOutPkgLen"> </param>[out]
/// <param name="piErrSXCode"> </param>[out]
/// <param name="pMsgPropery"> </param>[in/out]
/// <param name="iMillSecTimeo"> </param>[in]
/// <returns>0 </returns>
[DllImport("mrapi.dll", EntryPoint = "MrReceive3", CallingConvention = CallingConvention.StdCall, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern int MrReceive3(IntPtr pHandle, out IntPtr ppsPkg, out int piOutPkgLen, out int piErrSXCode, ref STUsgProperty pMsgPropery, int iMillSecTimeo);
//int _stdcall MrReceive3(void* pHandle, char** ppsPkg, int* piOutPkgLen, int* piErrSXCode, STUMsgProperty* pMsgPropery, int iMillSecTimeo);
/// <summary>
/// 13. 4
/// </summary>
/// <param name="pHandle"> , MrInit </param>[in]
/// <param name="ppsPkg"> , </param>[out]
/// <param name="piOutPkgLen"> </param>[out]
/// <param name="piErrSXCode"> </param>[out]
/// <param name="pMsgPropery"> </param>[in/out]
/// <param name="iMillSecTimeo"> </param>[in]
/// <returns>0 </returns>
[DllImport("mrapi.dll", EntryPoint = "MrReceive4", CallingConvention = CallingConvention.StdCall, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern int MrReceive4(IntPtr pHandle, out IntPtr ppsPkg, out int piOutPkgLen, out int piErrSXCode, ref STUsgProperty pMsgPropery, int iMillSecTimeo);
//int _stdcall MrReceive4(void* pHandle, char** ppsPkg, int* piOutPkgLen, int* piErrSXCode, STUMsgProperty* pMsgPropery, int iMillSecTimeo);
/// <summary>
/// 14.
/// </summary>
/// <param name="pHandle"> , MrInit </param>
/// <returns> </returns>
[DllImport("mrapi.dll", EntryPoint = "MrDestroy", CallingConvention = CallingConvention.StdCall, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern IntPtr MrDestroy(IntPtr pHandle);
//void _stdcall MrDestroy(void* pHandle)
/// <summary>
/// 15. API
/// </summary>
/// <param name="psBufVersion"> </param>
/// <param name="iBufLen"> </param>
/// <returns> </returns>
[DllImport("mrapi.dll", EntryPoint = "MrGetVersion", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern IntPtr MrGetVersion(StringBuilder psBufVersion, int iBufLen);
//void _stdcall MrGetVersion(char* psBufVersion,int iBufLen);
/// <summary>
/// 16.
/// </summary>
/// <param name="pHandle"> , MrInit <</param>
/// <param name="pMsgPropery"> </param>
/// <param name="iType">0 1 2 </param>
/// <returns>0 </returns>
[DllImport("mrapi.dll", EntryPoint = "MrRegRecvCondition", CallingConvention = CallingConvention.StdCall, SetLastError = true, CharSet = CharSet.Ansi)]
public static extern int MrRegRecvCondition(IntPtr pHandle, ref STUsgProperty pMsgPropery, int iType);
//int _stdcall MrRegRecvCondition(void* pHandle,STUMsgProperty* pMsgPropery,int iType);
#endregion
}
}