CyTangTP.dll
共提供三个函数,此文件拷贝在运行目录下。
在VB环境下声明如下:
在Module1中定义动态库函数;
Declare Function OpenComm Lib "CyTangTP.dll" (ByVal ComNo As Integer, ByVal Baud As Integer) As Long
Declare Function CloseComm Lib "CyTangTP.dll" (ByVal Handle_Of_Com As Long) As Integer
Declare Function SendMsg Lib "CyTangTP.dll" (ByVal Handle_Of_Com As Long, ByVal TPSet
As String, ByVal Msg As String) As Integer
现在,我们要在VC中调用这三个函数,实现代码如下:
HMODULE module
=
LoadLibrary(
"
CyTangTP.dll
"
);
typedef
long
(CALLBACK
*
pOpen)(
int
,
int
);
//
注意这里
typedef
long
(CALLBACK
*
pSend)(
long
,CString,CString);
//
注意这里
typedef
int
(CALLBACK
*
pClose)(
long
);
//
注意这里
if
(module)

...
{
//调用OpenComm
pOpen Open = (pOpen)GetProcAddress(module,"OpenComm");
long port;
if(Open!=NULL)

...{
port = Open(1,9600);
MessageBox("Open");
}
else
return;

//调用SendMsg
pSend Send = (pSend)GetProcAddress(module,"SendMsg");
int nSend = 1;
if(Send!=NULL)

...{
nSend = Send(port,"0,20,2,1,1,1,1,0,1","RabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN12345678901234567890欢迎光临东方信通科技");
CString str;
str.Format("%d",nSend);
MessageBox(str);
}
//调用CloseComm
pClose Close = (pClose)GetProcAddress(module,"CloseComm");
int nClose;
if(Close!=NULL)

...{
nClose = Close(port);
CString str;
str.Format("%d",nClose);
MessageBox(str);
}

FreeLibrary(module);
}