我试图从DLL调用一些nio函数,但不断获取Access违规读取位置错误。这是我的代码。
这些是我想要调用的函数。
typedef void ( *nio_read)(OUT IOSTAT *pIoStat,
IN OUT IOVSPEC *pIov,
IN OUT EGUREC *pEgu,
IN OUT IODATA *pIoData );
typedef void(*nio_paddr)(OUT IOSTAT *pIoStat, IN OUT IOVSPEC *pIov,
IN OUT EGUREC *pEgu, IN char *pszBuff);
typedef void(*nio_tick_enable)(IOSTAT *pIoStat, IOVSPEC *pIov);
typedef void(*nio_tick)(short int amount);
这是主要功能
int main(void)
{
nio_read _nio_read;
nio_tick _nio_tick;
nio_tick_enable _nio_tick_enable;
nio_paddr _nio_paddr;
IOSTAT *pIoStat = (IOSTAT *)malloc(sizeof(IOSTAT));
memset(pIoStat,0, sizeof(IOSTAT));
IOVSPEC *pIov = (IOVSPEC *)malloc(sizeof(IOVSPEC));
memset(pIov,0,sizeof(IOVSPEC));
EGUREC *pEgu = (EGUREC *)malloc(sizeof(EGUREC));
memset(pEgu,0,sizeof(EGUREC));
IODATA *pIoData = (IODATA *)malloc(sizeof(IODATA));
memset(pIoData,0,sizeof(IODATA));;
HINSTANCE hInstLibrary = LoadLibrary("J91STSR.dll");
if( hInstLibrary ) {
_nio_read=(nio_read)GetProcAddress(hInstLibrary,"nio_read");
_nio_paddr=(nio_paddr)GetProcAddress(hInstLibrary,"nio_paddr");
_nio_tick=(nio_tick)GetProcAddress(hInstLibrary,"nio_tick");
_nio_tick_enable=(nio_tick_enable)GetProcAddress(hInstLibrary,"nio_tick_enable");
printf("testttt \n");
}
if(_nio_read){
(_nio_read)(pIoStat, pIov,pEgu,pIoData);
}
if( hInstLibrary ) {
FreeLibrary(hInstLibrary );
}
}
我在此行收到错误
(_nio_read)(pIoStat, pIov,pEgu,pIoData);
我还是c ++的新手,我似乎无法弄清问题是什么。