EDN Admin
Well-known member
[background=#fafafa]Hello,[/background]
[background=#fafafa]I have CAN Dll program for my application,which was separately used.Now I have included the Drivers program into my application Program and I am having this error System Access Violation Exception:Attempted to read or write protected memory.Please help me what is error for.i am attaching the Dll code and Application code which is throwing this error.[/background]
[background=#fafafa]The CAN Dll Code[/background]
[background=#fafafa]int receive_data(unsigned char *data_output, int *MsgId, XLportHandle g_xlPortHandle){[/background]
[background=#fafafa]XLstatus xlStatus, xlStatus_new;[/background]
[background=#fafafa]XLevent xlEvent; [/background]
[background=#fafafa]unsigned int msgsrx=RECEIVE_EVENT_SIZE;[/background]
[background=#fafafa]char *local_data ="11111111";[/background]
[background=#fafafa]DWORD status;[/background]
[background=#fafafa]xlStatus_new = xlSetNotification(g_xlPortHandle, &h, 1); [/background]
[background=#fafafa]WaitForSingleObject(h,1);[/background]
[background=#fafafa]xlStatus = XL_SUCCESS;[/background]
[background=#fafafa]while(!xlStatus){[/background]
[background=#fafafa]msgsrx = RECEIVE_EVENT_SIZE;[/background]
[background=#fafafa]xlStatus = xlReceive(g_xlPortHandle, &msgsrx, &xlEvent);---------->Here is the error [/background]
[background=#fafafa]if ( xlStatus!=XL_ERR_QUEUE_IS_EMPTY ) {[/background]
[background=#fafafa]memcpy(data_output,xlEvent.tagData.msg.data,8);[/background]
[background=#fafafa]*MsgId = xlEvent.tagData.msg.id;[/background]
[background=#fafafa]return 0;[/background]
[background=#fafafa]}[/background]
[background=#fafafa]else{[/background]
[background=#fafafa]return XL_ERR_QUEUE_IS_EMPTY;[/background]
[background=#fafafa]}[/background]
[background=#fafafa]}[/background]
[background=#fafafa]}[/background]
[background=#fafafa]My Application Code which is the receiver thread for accessing the messages got onto the CAN bus.[/background]
[background=#fafafa]DWORD WINAPI Rcv_Msg(LPVOID param){[/background]
[background=#fafafa]int *MsgId = new int; //msg id from CAN[/background]
[background=#fafafa]int RcvVal; //0 = there is data in the queue; 1 = there is no data[/background]
[background=#fafafa]unsigned int uMsgId;[/background]
[background=#fafafa]*MsgId = 0;[/background]
[background=#fafafa]unsigned char CanData[8];[/background]
[background=#fafafa]unsigned int i = 0;[/background]
[background=#fafafa]unsigned int j = 0;[/background]
[background=#fafafa]unsigned int Startbit = 0;[/background]
[background=#fafafa]unsigned int Endbit = 0;[/background]
[background=#fafafa]float Offset = 0;[/background]
[background=#fafafa]float Resolution = 0;[/background]
[background=#fafafa]try {[/background]
[background=#fafafa]while(vThread_exit.Rcv_Msg){[/background]
[background=#fafafa]RcvVal = receive_data(CanData, MsgId,g_xlPortHandle_global);-------->Here is the error[/background]
[background=#fafafa]memcpy(&uMsgId,MsgId,4);[/background]
[background=#fafafa]UI64 RawCanData;[/background]
[background=#fafafa]if(RcvVal == 0){ //there is data in the queue[/background]
[background=#fafafa]switch(uMsgId){ //switch statement that parses the incoming message based ON the message id.[/background]
[background=#fafafa]So this program builded successfully and while executing it I am getting the error as[/background]
[background=#fafafa]Receive thread quit Unexpectedly[/background]
[background=#fafafa]system Access violation Exception:Attempted to read or write protected memory.This is often an indication that other memory is corrupt at[/background]
[background=#fafafa]xlreceive(int32,Uint32*,s_xl_event*)[/background]
[background=#fafafa]at receive_data(Byte*data_output,int32*MsgId,Int32 g_xlPortHandle).[/background]
[background=#fafafa]Please help me with this.[/background]
[background=#fafafa]Thanks in Advance.[/background]
View the full article
[background=#fafafa]I have CAN Dll program for my application,which was separately used.Now I have included the Drivers program into my application Program and I am having this error System Access Violation Exception:Attempted to read or write protected memory.Please help me what is error for.i am attaching the Dll code and Application code which is throwing this error.[/background]
[background=#fafafa]The CAN Dll Code[/background]
[background=#fafafa]int receive_data(unsigned char *data_output, int *MsgId, XLportHandle g_xlPortHandle){[/background]
[background=#fafafa]XLstatus xlStatus, xlStatus_new;[/background]
[background=#fafafa]XLevent xlEvent; [/background]
[background=#fafafa]unsigned int msgsrx=RECEIVE_EVENT_SIZE;[/background]
[background=#fafafa]char *local_data ="11111111";[/background]
[background=#fafafa]DWORD status;[/background]
[background=#fafafa]xlStatus_new = xlSetNotification(g_xlPortHandle, &h, 1); [/background]
[background=#fafafa]WaitForSingleObject(h,1);[/background]
[background=#fafafa]xlStatus = XL_SUCCESS;[/background]
[background=#fafafa]while(!xlStatus){[/background]
[background=#fafafa]msgsrx = RECEIVE_EVENT_SIZE;[/background]
[background=#fafafa]xlStatus = xlReceive(g_xlPortHandle, &msgsrx, &xlEvent);---------->Here is the error [/background]
[background=#fafafa]if ( xlStatus!=XL_ERR_QUEUE_IS_EMPTY ) {[/background]
[background=#fafafa]memcpy(data_output,xlEvent.tagData.msg.data,8);[/background]
[background=#fafafa]*MsgId = xlEvent.tagData.msg.id;[/background]
[background=#fafafa]return 0;[/background]
[background=#fafafa]}[/background]
[background=#fafafa]else{[/background]
[background=#fafafa]return XL_ERR_QUEUE_IS_EMPTY;[/background]
[background=#fafafa]}[/background]
[background=#fafafa]}[/background]
[background=#fafafa]}[/background]
[background=#fafafa]My Application Code which is the receiver thread for accessing the messages got onto the CAN bus.[/background]
[background=#fafafa]DWORD WINAPI Rcv_Msg(LPVOID param){[/background]
[background=#fafafa]int *MsgId = new int; //msg id from CAN[/background]
[background=#fafafa]int RcvVal; //0 = there is data in the queue; 1 = there is no data[/background]
[background=#fafafa]unsigned int uMsgId;[/background]
[background=#fafafa]*MsgId = 0;[/background]
[background=#fafafa]unsigned char CanData[8];[/background]
[background=#fafafa]unsigned int i = 0;[/background]
[background=#fafafa]unsigned int j = 0;[/background]
[background=#fafafa]unsigned int Startbit = 0;[/background]
[background=#fafafa]unsigned int Endbit = 0;[/background]
[background=#fafafa]float Offset = 0;[/background]
[background=#fafafa]float Resolution = 0;[/background]
[background=#fafafa]try {[/background]
[background=#fafafa]while(vThread_exit.Rcv_Msg){[/background]
[background=#fafafa]RcvVal = receive_data(CanData, MsgId,g_xlPortHandle_global);-------->Here is the error[/background]
[background=#fafafa]memcpy(&uMsgId,MsgId,4);[/background]
[background=#fafafa]UI64 RawCanData;[/background]
[background=#fafafa]if(RcvVal == 0){ //there is data in the queue[/background]
[background=#fafafa]switch(uMsgId){ //switch statement that parses the incoming message based ON the message id.[/background]
[background=#fafafa]So this program builded successfully and while executing it I am getting the error as[/background]
[background=#fafafa]Receive thread quit Unexpectedly[/background]
[background=#fafafa]system Access violation Exception:Attempted to read or write protected memory.This is often an indication that other memory is corrupt at[/background]
[background=#fafafa]xlreceive(int32,Uint32*,s_xl_event*)[/background]
[background=#fafafa]at receive_data(Byte*data_output,int32*MsgId,Int32 g_xlPortHandle).[/background]
[background=#fafafa]Please help me with this.[/background]
[background=#fafafa]Thanks in Advance.[/background]
View the full article