開發環境: WinXP Pro(SP
接口庫版本: CMPP
該例程演示了如何在C#裡面調用VC
由於我使用C#剛兩天
CMPP
#define DllExport extern
DllExport int __stdcall Cmpp
DllExport int __stdcall Cmpp
DllExport int __stdcall Cmpp
在C#裡面如何調用API
下面是C#下面的完整的調用代碼
//Class
using System;
// 該名稱空間包含了在Visual C#中調用API的一些必要集合
using System
// 使用Sleep方法需要的命名空間
using System
namespace CMPPAPI_Sample_CSharp
{
//
//
//
[StructLayout(LayoutKind
public struct CMPP_HEAD
{
public uint nTotalLength;
public uint nCommandId;
public uint nSeqId;
}
[StructLayout(LayoutKind
public struct CMPP_CONNECT
{
[MarshalAs(UnmanagedType
public string sSourceAddr;
[MarshalAs(UnmanagedType
public string sAuthSource;
public byte cVersion;
public uint nTimeStamp;
}
[StructLayout(LayoutKind
public struct CMPP_CONNECT_RESP
{
public byte uchStatus;
[MarshalAs(UnmanagedType
public string sAuthISMG;
public byte cVersion;
}
[StructLayout(LayoutKind
public struct CMPP_SUBMIT_RESP
{
public long nMsgid;
public byte uchResult;
}
[StructLayout(LayoutKind
public struct CMPP_STATUS_REPORT
{
public long nMsgid;
[MarshalAs(UnmanagedType
public string sStat;
[MarshalAs(UnmanagedType
public string sSubmitTime;
[MarshalAs(UnmanagedType
public string sDoneTime;
[MarshalAs(UnmanagedType
public string sDestTerminalId;
public uint nSmscSeq;
}
[StructLayout(LayoutKind
public struct CMPP_MO_MSGCONTENT
{
[MarshalAs(UnmanagedType
public string sMsgcontent;
public CMPP_STATUS_REPORT csr;
}
[StructLayout(LayoutKind
public struct CMPP_DELIVER
{
public long nMsgid;
[MarshalAs(UnmanagedType
public string sDestid;
[MarshalAs(UnmanagedType
public string sServiceid;
public byte uchTppid;
public byte uchTpudhi;
public byte uchMsgfmt;
[MarshalAs(UnmanagedType
public string sSrcterminalid;
public byte uchRegisteredDelivery;
public byte uchMsglength;
public CMPP_MO_MSGCONTENT mo_msg;
[MarshalAs(UnmanagedType
public string sReserved;
}
[StructLayout(LayoutKind
public struct CMPP_SUBMIT
{
public long nMsgid;
public byte uchPkTotal;
public byte uchPkNumber;
public byte uchRegisteredDelivery;
public byte uchMsgLevel;
[MarshalAs(UnmanagedType
public string sServiceId;
public byte uchFeeUserType;
[MarshalAs(UnmanagedType
public string sFeeTerminalId;
public byte uchTpPid;
public byte uchTpUdhi;
public byte uchMsgFmt;
[MarshalAs(UnmanagedType
public string sMsgSrc;
[MarshalAs(UnmanagedType
public string sFeeType;
[MarshalAs(UnmanagedType
public string sFeeCode;
[MarshalAs(UnmanagedType
public string sValidTime;
[MarshalAs(UnmanagedType
public string sAtTime;
[MarshalAs(UnmanagedType
public string sSrcId;
public byte uchDstUsrTl;
[MarshalAs(UnmanagedType
public string sDstTerminalId;
public byte uchMsgLength;
[MarshalAs(UnmanagedType
public string sMsgContent;
[MarshalAs(UnmanagedType
public string sReserved;
}
[StructLayout(LayoutKind
public struct CMPP_QUERY
{
[MarshalAs(UnmanagedType
public string sTime;
public byte uchQueryType;
[MarshalAs(UnmanagedType
public string sQueryCode;
[MarshalAs(UnmanagedType
public string sReserved;
}
[StructLayout(LayoutKind
public struct CMPP_QUERY_RESP
{
[MarshalAs(UnmanagedType
public string sTime;
public byte uchQueryType;
[MarshalAs(UnmanagedType
public string sQueryCode;
public uint nMTTLMsg; //從SP接收消息總數
public uint nMTTLUsr; //從SP接收用戶總數
public uint nMTScs; //成功轉發數量
public uint nMTWT; //待轉發數量
public uint nMTFL; //轉發失敗數量
public uint nMOScs; //向SP成功送達數量
public uint nMOWT; //向SP待送達數量
public uint nMOFL; //向SP送達失敗數量
}
[StructLayout(LayoutKind
public struct CMPP_CANCEL
{
public long nMsgid;
}
[StructLayout(LayoutKind
public struct CMPP_CANCEL_RESP
{
public byte uchSuccessId;
}
[StructLayout(LayoutKind
public struct CMPP_ACTIVETEST_RESP
{
public byte uchReserved;
}
[StructLayout(LayoutKind
public struct CMPP_BODY
{
public CMPP_CONNECT_RESP pk_connectresp;
public CMPP_SUBMIT_RESP pk_submitresp;
public CMPP_QUERY_RESP pk_queryre
From:http://tw.wingwit.com/Article/os/youhua/201311/10754.html