调dll出现内存溢出
我是这样做的,建立一个基于对话框的程序
然后将我所需要的函数变量设成全局变量
typedef void (*AddFunc)(int,BYTE);
AddFunc _DlPortWritePortUchar;
在OnInitDialog()中
{
......
hInstLibrary = LoadLibrary("DLPORTIO.dll");
if (hInstLibrary == NULL)
{
FreeLibrary(hInstLibrary);
}
_DlPortWritePortUchar = (AddFunc)GetProcAddress(hInstLibrary, "DlPortWritePortUchar");
if (_DlPortWritePortUchar == NULL)
{
FreeLibrary(hInstLibrary);
}
.........
}
hInstLibrary已经被我定义成该对话框的成员变量
之后将_DlPortWritePortUchar封装
void CMy111Dlg::DriveCard(int port, BYTE value)
{
_DlPortWritePortUchar(port,0xAA); //start
Sleep(20);
_DlPortWritePortUchar(port,0x00); //command: 00->write, 01->read,02->
Sleep(20);
_DlPortWritePortUchar(port,0x20); //address: high
Sleep(20);
_DlPortWritePortUchar(port,0x00); //address:low
Sleep(20);
_DlPortWritePortUchar(port,0x01); //length
Sleep(20);
_DlPortWritePortUchar(port,value);//random(257));
}
经跟踪测试第一次调用就出现内存溢出的错误.
请各位指点,我哪里错了?