通达信的调用dll函数编号7手机怎么建立的
这样就能实现在ie上直接对**进行操作。而我要封装的这个动态库,厂家只提供了一个单的动态库和一百多字的说明,也就是说明一下动态库中有机个函数和其对应的参数。也就是厂家就连动态库对应的头文件也没有提供。接到这个任务后,我第一想到的是用vc的atl来实现它。你问我为什么要用atl也不用别的,如cb、delphi之类的。我只能说我觉得写activex还是用vc好;况且还要对硬件进行操作,这样一来当然是用vc了。别说我没提醒你,用cb、delphi之类的有可能会出现预想不到的惊奇。。。。现在让我带着进入正题吧!先用atlcomappwizard生成一个名叫posactivex的工程,生成时系统会问你是生成dll还是exe。当然是dll的了。生成好后加入一个接口叫iposctrl,当然了要在web上用,所以生成的接口一定是要小所以选择litecontrol的。你可别问我怎么加入,如果这都不会,那我写的这文章是不适合你看的。所以等你学会加入接口后再看。接口加好后,我就要实现方法了。首先用接口一般都要对其进行初始化。所以加入一个叫init(shortncom)的接口方法,该方法完成加载dll和dll中的功能函数,还有就是打开对**进行操作的com口;还有一个是修改**的时间的方法叫modifyposdt(bstrbstrdt);还有个是清空**中数据的方法--emptypos()。最后,当你不想用时就要关闭所打开的com口--quit()。在生成接口iposctrl时同时会生成cposctrl类。我有个习惯,就是我一般是把实现方法都写在类中,而接口只时输出该类中你想输出的方法。所以在类中我就写了以下几个方法:initdll()----加载dll库和其中的功能函数;exitdll()----卸载dll库,用完后不卸载是在占用内存。所以它是少不了的。setposdatetime(char*pchdt)---设置**的时间。clearpos()----清空**中的记录。在类中我就写了这几方法了。在说一下我要输出的接口方法有:iint(shortncom)----初化接口,为调用做准备。quit()----退出程序时,调用它退出接口调用。modifyposdt(bstrbstrdt)----设置**时间。emptypos()----清空**数据。完了就这么多。现在来看看我的源程序吧!//posctrl.cpp:implementationofcposctrl#include"stdafx.h"#include"posactivex.h"#include"posctrl.h"///////////////////////////////////////////////////////////////////////////////cposctrl///////////////////////////////////////////////////////////////////////////////police.dll所用到的常量定义/////////////////////////////////////////////////////////////////////////////#definecom_uprecord1#definecom_uppolicelen2#definecom_upsimpledatalen3#definecom_upsimplepun**hlen4#definecom_upgeneraldatalen5#definecom_upgeneralpun**hlen6#definecom_emptypolice7#definecom_emptysimpledata8#definecom_emptysimplepun**h9#definecom_emptygeneraldata10#definecom_emptygeneralpun**h11#definecom_downrecord0x80#definecom_downstreetcodelen0x81#definecom_downblackl**tlen0x82#definecom_downpeccancysimplelen0x83#definecom_downpeccancygenerallen0x84#definecom_downdatetime0x85#definecom_exit0x86#definecom_init0x87#defineerr_upsimpledatalen0#defineerr_upsimplepun**hlen1#defineerr_upgeneraldatalen2#defineerr_upgeneralpun**hlen3#defineerr_uppolicelen4#defineerr_uprecord5#defineerr_downstreetcodelen6#defineerr_downsimplepeccancycodelen7#defineerr_downgeneralpeccancycodelen8#defineerr_downblackl**t9#defineerr_downdatetime10#defineerr_emptydata11#defineerr_getcode12;#defineconst_terminator0x20/////////////////////////////////////////////////////////////////////////////////#pragmadata_seg("mydata")statichinstancedllinst=**;//动态库句柄#pragmadata_seg()//handlehcom;//com串口句柄///////////////////////////////////////////////////////////////////////////////////police.dll动态库函数功能定义/////////////////////////////////////////////////////////////////////////////////handle(__stdcall*init_comm)(lpstrstr);//初始化通信口byte(__stdcall*exit)(handlehcom);//关闭通信口byte(__stdcall*protocol)(handlehcom,bytecmd,bytelen,byte*_dt,byte*prlen,byte*prdt);//通信协议byte(__stdcall*pipe_control)(handlehcom,bytemode);//多路控制typedefbyte(__stdcall*dev_escape)(handlehcom);//断开多路控制///////////////////////////////////////////////////////////////////////////////cposctrl//----------------------------------------------------------------------------////功能:加载police.dll动态库和其中的一些功能函数//输入/输出参数:无//版本:1.0//修改://----------------------------------------------------------------------------//voidcposctrl::initdll(){dllinst=loadlibrary("police.dll");if(dllinst!=**){init_comm=(handle(__stdcall*)(lpstr))getprocaddress(dllinst,"init_comm");exit=(byte(__stdcall*)(handle))(getprocaddress(dllinst,"exit"));protocol=(byte(__stdcall*)(handle,byte,byte,byte*_dt,byte*prlen,byte*prdt))(getprocaddress(dllinst,"protocol"));pipe_control=(byte(__stdcall*)(handle,byte))(getprocaddress(dllinst,"pipe_control"));dev_escape=(byte(__stdcall*)(handle))(getprocaddress(dllinst,"dev_escape"));}else{::**box(**,"加载动态库失败!","提示信息",mb_ok|mb_icon**rmation);exit(0);}}//----------------------------------------------------------------------------////功能:释放动态库//输入/输出参数:无//版本:1.0//修改://----------------------------------------------------------------------------//voidcposctrl::exitdll(){if(dllinst!=**)freelibrary(dllinst);}//----------------------------------------------------------------------------////功能:控件接口方法,对外提供关闭串口,释放动态库。//输入/输出参数:无//版本:1.0//修改://----------------------------------------------------------------------------//stdmethodimpcposctrl::quit(){//todo:addyourimplementationcodehere(*exit)(hcom);exitdll();::**box(**,"关闭com口成功","提示信息",mb_ok|mb_icon**rmation);returns_ok;}stdmethodimpcposctrl::get_comno(short*pval){//todo:addyourimplementationcodehere*pval=m_comno;returns_ok;}stdmethodimpcposctrl::put_comno(shortnewval){//todo:addyourimplementationcodeherem_comno=newval;returns_ok;}//----------------------------------------------------------------------------////功能:提供初化动态库的对外接口,并实现打开口串口的功能。//输入/输出参数:11--要打开的串口号。 20210311