using System;
using ;
using ;
using ;
using ;
using ;
namespace FDEP
{
/// <summary>
/// Luo Xucheng
/// Shenzhen Certificate Function Conversion
/// </summary>
public class ImportDLL
{
#region * Constant definition
//*****************************************************************
//Protocol type constant
//Name �
//MR_PROTOCOLTYPE_MRSTANDAND
//MR_PROTOCOLTYPE_SELFCUSTOM 0xFF User-defined protocol type
/// <summary>
/// Protocol type constant
/// </summary>
public const uint MR_PROTOCOLTYPE_MRSTANDAND = 0x01; // SBSP standard business protocol.
public const uint MR_PROTOCOLTYPE_SELFCUSTOM = 0xFF; // User-defined protocol type.
//*****************************************************************
//Message identification bit constant
//Name �
//MR_MSGFLAG_PERSIST Not currently supported
//MR_MSGFLAG_COMPRESS
/// <summary>
/// Message flag bit constant
/// </summary>
public const uint MR_MSGFLAG_PERSIST = 0x01; // Persistent message flag for reliable transmission.
public const uint MR_MSGFLAG_COMPRESS = 0x02; // Compression flag, compression transmission is required.
//*****************************************************************
//Length constant
//Name �
//MR_MAXLEN_ADDR �
//MR_MAXLEN_PKGID �
//MR_MAXLEN_USERDATA �
//MR_FIXLEN_EXPIREDABSTIME
/// <summary>
/// Message flag bit constant
/// </summary>
public const int MR_MAXLEN_ADDR = 64; // Maximum length of user ID and application ID.
public const int MR_MAXLEN_PKGID = 64; // Maximum length of message packet identification.
public const int MR_MAXLEN_USERDATA = 256; // The maximum length of data retained by the user.
public const int MR_FIXLEN_EXPIREDABSTIME = 20; // The expiration absolute time is fixed.
//*****************************************************************
//The function returns the error value
//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 * Definition of structure
/// <summary>
/// Various attributes used to represent a message
/// </summary>
[StructLayout()]
public struct STUsgProperty
{
[MarshalAs(, SizeConst = MR_MAXLEN_ADDR)]
public string m_szSourceUserID;//MR_MAXLEN_ADDR Source user ID, string ending with "\0"
[MarshalAs(, SizeConst = MR_MAXLEN_ADDR)]
public string m_szSourceAppID;//MR_MAXLEN_ADDR Source application identifier, string ending with "\0"
[MarshalAs(, SizeConst = MR_MAXLEN_ADDR)]
public string m_szDestUserID;//MR_MAXLEN_ADDR Destination user ID, string ending with "\0"
[MarshalAs(, SizeConst = MR_MAXLEN_ADDR)]
public string m_szDestAppID;//MR_MAXLEN_ADDR The purpose application identifier, a string ending with "\0"
[MarshalAs(, SizeConst = MR_MAXLEN_PKGID)]
public string m_szPkgID;//MR_MAXLEN_PKGID The packet identifier of the message packet, a string ending with "\0", or generated by the user calling the MrCreatePkgID function, or is empty (i.e. '\0')
[MarshalAs(, SizeConst = MR_MAXLEN_PKGID)]
public string m_szCorrPkgID;//MR_MAXLEN_PKGID Related package identifier, string ending with "\0" for users to use
[MarshalAs(, SizeConst = MR_MAXLEN_USERDATA)]
public string m_szUserData1;//MR_MAXLEN_USERDATA User data 1, a string ending with "\0" for users to use
[MarshalAs(, SizeConst = MR_MAXLEN_USERDATA)]
public string m_szUserData2;//MR_MAXLEN_USERDATA User data 2, a string ending with "\0" for users to use
[MarshalAs(, SizeConst = MR_FIXLEN_EXPIREDABSTIME)]
public string m_szExpiredAbsTime;//MR_FIXLEN_EXPIREDABSTIME The expiration time of this message is a string ending in "\0" and the format is "YYYY-MM-DD HH:MM:SS". It can also be empty. At this time, if the destination user is not online, or the destination application is not connected, the message expires immediately.
public byte m_ucFlag;//Message ID consists of 8 binary bits, and the meanings of each bit are as follows: bit 0 -- 1 means a persistent message, which requires reliable transmission and is not supported for the time being;
//Bit 1 -- is 1 to indicate that the message needs to be compressed and transmitted.
public byte m_ucProtocolType;//Protocol type identification, the value can be one of the following: MR_PROTOCOLTYPE_MRSTANDAND 0x01 Standard business protocol specified by FDEP
//MR_PROTOCOLTYPE_SELFCUSTOM 0xFF User-defined protocol type
}
/// <summary>
/// Used to define various information required to establish a connection with the access client
/// </summary>
[StructLayout()]
public struct STUConnInfo
{
[MarshalAs(, SizeConst = 16)]
public string m_szMRIP;//The IP address of the access client message router, a string ending with "\0", format as ""
public UInt16 m_usMRPort;//Connection port to access the client message router
[MarshalAs(, SizeConst = 16)]
public string m_szMRIPBak;//The IP address of the backup message router can be empty if the backup message router is not set.
public UInt16 m_usMRPortBak;//The connection port of the backup message router can be 0 if the backup message router is not set.
}
#endregion
#region * Function definition
/// <summary>
/// Defined callback function
/// </summary>
/// <param name="psPkg">Message packet buffer to be sent</param>
/// <param name="iPkgLen">Message packet length in the buffer</param>
/// <param name="pMsgPropery">Message Package Properties</param>
/// <param name="pvUserData">User data for callback function</param>
/// <returns></returns>
[UnmanagedFunctionPointerAttribute()]
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. Initialize, obtain relevant resources, and try to establish a connection with the access client FDAP
/// </summary>
/// <param name="psAppID">Application ID of this application</param>[in]
/// <param name="psPasswd">The password set by this application on the access client service side, and the password must match the preset before it can continue</param>[in]
/// <param name="onReceive">Callback function when receiving message packet</param>[in]
/// <param name="oConnInfo">access client connection information</param>[in]
/// <param name="pvUserData">User data for callback function</param>[in]
/// <returns>NULL initialization failed. Non-NULL initialization was successful. Return a connection handle, and the handle will be used as a parameter for other function calls</returns>
[DllImport("", EntryPoint = "MrInit", CallingConvention = , SetLastError = true, CharSet = )]
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. Initialize, obtain relevant resources, and try to establish a connection with the access client FDAP
/// </summary>
/// <param name="psUserCertID">User ID of this application</param>[in]
/// <param name="psAppID">Application ID of this application</param>[in]
/// <param name="psPasswd">The password set by this application on the access client service side, and the password must match the preset before it can continue</param>[in]
/// <param name="onReceive">Callback function when receiving message packet</param>[in]
/// <param name="oConnInfo">access client connection information</param>[in]
/// <param name="pvUserData">User data for callback function</param>[in]
/// <returns>NULL initialization failed. Non-NULL initialization was successful. Return a connection handle, and the handle will be used as a parameter for other function calls</returns>
[DllImport("", EntryPoint = "MrInit1", CallingConvention = , SetLastError = true, CharSet = )]
public static extern IntPtr MrInit1(string psUserCertID, string psAppID, string psPasswd, OnReceiveCallBack onReceive, STUConnInfo oConnInfo, IntPtr pvUserData);
/// <summary>
/// 3. Initialization function when connecting FDAP. This function initializes FDEAPI, allocates and obtains relevant resources, and tries to establish a communication connection with the access client
/// </summary>
/// The handle returned by the <param name="pHandle"> function, which will be used as a parameter for other function calls</param>[out]
/// <param name="psUserCertID">User ID of this application</param>[in]
/// <param name="psAppID">Application ID of this application</param>[in]
/// <param name="psPasswd">The password set by this application on the access client must match the preset before it can continue</param>[in]
/// <param name="pMsgProperty">Message Package Properties</param>[in]
/// <param name="onReceive">Callback function when receiving message packet</param>[in]
/// <param name="oConnInfo">access client connection information</param>[in]
/// <param name="pvUserData">User data for callback function</param>[in]
/// <param name="iThreadCount">Number of threads calling the back function OnReceive</param>[in]
/// <returns>None</returns>
[DllImport("", EntryPoint = "MrInit1Ex1", CallingConvention = , SetLastError = true, CharSet = )]
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. Initialization function when connecting FDAP. This function initializes FDEAPI, allocates and obtains relevant resources, and tries to establish a communication connection with the access client
/// </summary>
/// The handle returned by the <param name="pHandle"> function, which will be used as a parameter for other function calls</param>[out]
/// <param name="psAppID">Application ID of this application</param>[in]
/// <param name="psPassws">The password set by this application on the access client must match the preset before it can continue</param>[in]
/// <param name="pOnRecvMsgPropery">This is the reception condition of the callback function OnReceive. If no conditions are required, you can fill in NULL</param>[in]
/// <param name="onReceive">Callback function when receiving message packet</param>[in]
/// <param name="pConnInfo">access client connection information</param>[in]
/// <param name="pvUserData">User data for callback function</param>[in]
/// <param name="iThreadCount">Number of threads calling the back function OnReceive</param>
/// <returns>None</returns>
[DllImport("", EntryPoint = "MrInit2", CallingConvention = , SetLastError = true, CharSet = )]
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. Determine whether the connection with the exchange center is normal
/// </summary>
/// <param name="pHandle">Connect the handle, the value returned when MrInit is called</param>
/// <returns>0 is not normal 1 is normal</returns>
[DllImport("", EntryPoint = "MrIsLinkOK", CallingConvention = , SetLastError = true, CharSet = )]
public static extern int MrIsLinkOK(IntPtr pHandle);
//int _stdcall MrIsLinkOK(void* pHandle)
/// <summary>
/// 6. Message package identification generation function
/// </summary>
/// <param name="pHandle">Connect the handle, the value returned when MrInit is called</param>[in]
/// <param name="szPkgID">generated message package ID</param>[out]
/// <returns>0 Success Other Failed</returns>
[DllImport("", EntryPoint = "MrCreatePkgID", CallingConvention = , SetLastError = true, CharSet = )]
public static extern int MrCreatePkgID(IntPtr pHandle, StringBuilder szPkgID);
//int _stdcall MrCreatePkgID(void* pHandle,char szPkgID[MR_MAXLEN_PKGID])
/// <summary>
/// 7. Message packet sending function
/// </summary>
/// <param name="pHandle">Connect the handle, the value returned when MrInit is called</param>[in]
/// <param name="psPkg">Message packet buffer to be sent</param>[in]
/// <param name="iPkgLen">Message packet length in the buffer</param>[in]
/// <param name="pMsgPropery">Message Package Properties</param>[in/out]
/// <param name="iMillSecTimeo">Maximum timeout for reception in millimeters</param>[in]
/// <returns>0 Success Other Failed</returns>
[DllImport("", EntryPoint = "MrSend", CallingConvention = , SetLastError = true, CharSet = )]
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. Message Packet Receive Function 1
/// </summary>
/// <param name="pHandle">Connect the handle, the value returned when MrInit is called</param>[in]
/// <param name="ppsPkg">Double pointer, return the memory pointed to by the package</param>[out]
/// <param name="piOutPkgLen">The actual length of the message packet received</param>[out]
/// <param name="pMsgPropery">Receive conditions</param>[in/out]
/// <param name="iMillSecTimeo">Maximum timeout for reception in millimeters</param>[in]
/// <returns>0 Success Other Failed</returns>
[DllImport("", EntryPoint = "MrReceive1", CallingConvention = , SetLastError = true, CharSet = )]
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. Message package memory release function
/// </summary>
/// <param name="psPkg">Pointer returned by the second parameter of MrReceivel1 function</param>[in]
/// <returns>None</returns>
[DllImport("", EntryPoint = "MrReceive1_FreeBuf", CallingConvention = , SetLastError = true, CharSet = )]
public static extern IntPtr MrReceive1_FreeBuf(string psPkg);
//void _stdcall MrReceive1_FreeBuf(char* psPkg);
/// <summary>
/// 10. Message package browsing function
/// </summary>
/// <param name="pHandle">Connect the handle, the value returned when MrInit is called</param>[in]
/// <param name="piOutPkgLen">The actual length of the message packet received</param>[out]
/// <param name="pMsgPropery">Receive conditions</param>[in/out]
/// <param name="iMillSecTimeo">Maximum timeout for reception in millimeters</param>[in]
/// <returns>0 Success Other Failed</returns>
[DllImport("", EntryPoint = "MrBrowse", CallingConvention = , SetLastError = true, CharSet = )]
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. Message Packet Receive Function 2
/// </summary>
/// <param name="pHandle">Connect the handle, the value returned when MrInit is called</param>[in]
/// <param name="ppsPkg">Double pointer, return the memory pointed to by the package</param>[out]
/// <param name="piOutPkgLen">The actual length of the message packet received</param>[out]
/// <param name="iBufLenIn">Message Packet Buffer Size</param>[out]
/// <param name="pMsgPropery">Receive conditions</param>[in/out]
/// <param name="iMillSecTimeo">Maximum timeout for reception in millimeters</param>[in]
/// <returns>0 Success Other Failed</returns>
[DllImport("", EntryPoint = "MrReceive2", CallingConvention = , SetLastError = true, CharSet = )]
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. Message Packet Receive Function 3
/// </summary>
/// <param name="pHandle">Connect the handle, the value returned when MrInit is called</param>[in]
/// <param name="ppsPkg">Double pointer, return the memory pointed to by the package</param>[out]
/// <param name="piOutPkgLen">The actual length of the message packet received</param>[out]
/// <param name="piErrSXCode">Cause code for exchange error</param>[out]
/// <param name="pMsgPropery">Receive conditions</param>[in/out]
/// <param name="iMillSecTimeo">Maximum timeout for reception in millimeters</param>[in]
/// <returns>0 Success Other Failed</returns>
[DllImport("", EntryPoint = "MrReceive3", CallingConvention = , SetLastError = true, CharSet = )]
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. Message Packet Receive Function 4
/// </summary>
/// <param name="pHandle">Connect the handle, the value returned when MrInit is called</param>[in]
/// <param name="ppsPkg">Double pointer, return the memory pointed to by the package</param>[out]
/// <param name="piOutPkgLen">The actual length of the message packet received</param>[out]
/// <param name="piErrSXCode">Cause code for exchange error</param>[out]
/// <param name="pMsgPropery">Receive conditions</param>[in/out]
/// <param name="iMillSecTimeo">Maximum timeout for reception in millimeters</param>[in]
/// <returns>0 Success Other Failed</returns>
[DllImport("", EntryPoint = "MrReceive4", CallingConvention = , SetLastError = true, CharSet = )]
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. Release resources
/// </summary>
/// <param name="pHandle">Connect the handle, the value returned when MrInit is called</param>
/// <returns>None</returns>
[DllImport("", EntryPoint = "MrDestroy", CallingConvention = , SetLastError = true, CharSet = )]
public static extern IntPtr MrDestroy(IntPtr pHandle);
//void _stdcall MrDestroy(void* pHandle)
/// <summary>
/// 15. Obtain the version number of this API
/// </summary>
/// <param name="psBufVersion">Returned version number</param>
/// <param name="iBufLen">version number length</param>
/// <returns>None</returns>
[DllImport("", EntryPoint = "MrGetVersion", CallingConvention = , CharSet = )]
public static extern IntPtr MrGetVersion(StringBuilder psBufVersion, int iBufLen);
//void _stdcall MrGetVersion(char* psBufVersion,int iBufLen);
/// <summary>
/// 16. Registration package push conditions
/// </summary>
/// <param name="pHandle">Connect the handle, the value returned when MrInit is called <</param>
/// <param name="pMsgPropery">Structural entity of message</param>
/// <param name="iType">0 Add a condition 1 Delete a condition 2 Clear all conditions</param>
/// <returns>0 Success Other Failed</returns>
[DllImport("", EntryPoint = "MrRegRecvCondition", CallingConvention = , SetLastError = true, CharSet = )]
public static extern int MrRegRecvCondition(IntPtr pHandle, ref STUsgProperty pMsgPropery, int iType);
//int _stdcall MrRegRecvCondition(void* pHandle,STUMsgProperty* pMsgPropery,int iType);
#endregion
}
}