별도로 사용 된 응용 프로그램 용 CAN Dll 프로그램이 있습니다. 이제 Driver Program을 내 응용 프로그램에 포함 시켰습니다.이 오류가 발생했습니다. System Access Violation Exception:Attempted to read or write protected memory
. 오류는 무엇입니까? 이 오류를 던지고있는 DLL 코드와 응용 프로그램 코드를 첨부하고 있습니다.시스템 액세스 위반 예외 : 보호 된 메모리를 읽거나 쓰려고 시도했습니다.
캔의 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).
아마도 'xlEvent.tagData.msg.data' 버퍼를 제공해야합니까? xlEvent는 초기화가 필요합니까? – noelicus
이지만 xlEvent.tagData.msg.data는 버퍼 data_output으로 복사됩니다. – bobby2387
xlSetNotification 또는 WaitForSingleObject에서 오류를 확인하지 않습니다. 어느 쪽이든 또는 둘 다 실패 할 수 있으며 이는 다운 스트림에서 충돌을 일으킬 수 있습니다. 또한, h에 대한 선언이 없습니다. 그것은 무엇이며 어디에 정의되어 있습니까? –