我有我的应用程序的CAN Dll程序,它是单独使用的。现在,我已将驱动程序包含在我的应用程序中,并且出现此错误System Access Violation Exception:Attempted to read or write protected memory。错误是用来做什么的?我附上了Dll代码和应用程序代码,这是抛出这个错误。
CAN Dll代码
int receive_data(unsigned char *data_output, int *MsgId, XLportHandle g_xlPortHandle){
XLstatus xlStatus, xlStatus_new;
XLevent xlEvent;
unsigned int msgsrx=RECEIVE_EVENT_SIZE;
char *local_data ="11111111";
DWORD status;
xlStatus_new = xlSetNotification(g_xlPortHandle, &h, 1);
WaitForSingleObject(h,1);
xlStatus = XL_SUCCESS;
while(!xlStatus){
msgsrx = RECEIVE_EVENT_SIZE;
xlStatus = xlReceive(g_xlPortHandle, &msgsrx, &xlEvent);---------->Here is the error
if ( xlStatus!=XL_ERR_QUEUE_IS_EMPTY ) {
memcpy(data_output,xlEvent.tagData.msg.data,8);
*MsgId = xlEvent.tagData.msg.id;
return 0;
}
else{
return XL_ERR_QUEUE_IS_EMPTY;
}
}
}所以这个程序构建成功了,当我执行它的时候,我得到的错误是
Receive thread quit Unexpectedly
system Access violation Exception:Attempted to read or write protected memory.This is often an indication that other memory is corrupt at
xlreceive(int32,Uint32*,s_xl_event*)
at receive_data(Byte*data_output,int32*MsgId,Int32 g_xlPortHandle).发布于 2017-04-10 17:28:12
由于缺少XLevent结构的初始化,我也遇到了相同/类似的错误。
这可以通过初始化列表来实现:
XLevent xlEvent = {0};或者,如果您已经在使用动态内存管理,那么memset就可以做到这一点:
XLevent xlEvent;
memset(&xlEvent, 0, sizeof(xlEvent));它们是部分等价的(输出将是相同的)。有关更多信息,请查看此帖子:what is the difference between struct {0} and memset 0
https://stackoverflow.com/questions/15481515
复制相似问题