详细介绍C#调用API
该例程演示了C#调用API函数,而且回调函数的参数包含结构体,使用C#的委托和IntPtr方法实现.由于我使用C#刚两天,这是我写的第一个C#程序,因此例程写的可能有点粗糙,但是编译和运行完全没有问题.CMPP2.0的API封装成了标准C调用API的方法,提供以下三个接口,使用的时候只要有CMPPAPI.dll就可以了.
#define DllExport extern "C" __declspec(dllexport) DllExport int __stdcall Cmpp2Start(LPCTSTR pchSmgIp int nMtPort int nMoPort LPCTSTR pchUserName LPCTSTR pchUserPwd unsigned char uchVersion void (__stdcall *OnSmgMsg)(CMPP_SMGTOSP* css) int nConnType void (__stdcall *OnLogFile)(LPCTSTR str)); DllExport int __stdcall Cmpp2Submit( unsigned char uchPKtotal unsigned char uchPKnumber unsigned char uchNeedreport unsigned char uchMsglevel LPCTSTR pchServiceid unsigned char uchFeeusertype LPCTSTR pchFeeterminalid unsigned char uchTppid unsigned char uchTpudhi unsigned char uchMsgfmt LPCTSTR pchMsgsrc LPCTSTR pchFeetype LPCTSTR pchFeecode LPCTSTR pchValidtime LPCTSTR pchAttime LPCTSTR pchSrcid unsigned char uchDestusrtl LPCTSTR pchDestterminalid unsigned char uchMsglen LPCTSTR pchMsgcontent); DllExport int __stdcall Cmpp2Release();
C#调用API,如何声明结构体,如何使用委托实现回调函数,如何实现使用自定义结构体作为参数的回调函数,请仔细查看例程源码。注意:CMPPAPI.dll要和可执行文件放到同一个目录下,或者放到可执行文件能找到的目录,或者放到系统目录下(如:C:\windows \system32).
相关推荐
chensen 2020-11-14
leihui00 2020-09-16
二十不悔三十而立 2020-08-19
shining0 2020-08-02
TyrionZK 2020-07-26
TreasureZ 2020-07-26
natloc 2020-07-19
Bonrui编程路 2020-07-18
TyrionZK 2020-07-18
TyrionZK 2020-07-04
TreasureZ 2020-06-25
TreasureZ 2020-06-20
TreasureZ 2020-06-16
jameszgw 2020-06-14
Bonrui编程路 2020-06-13
Bonrui编程路 2020-06-07