-
March 17th, 2013, 10:10 AM
#1
System Access violation exception:Attempted to read or write protected memory..Help!
Hello,
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.
[CODE]
The CAN Dll Code
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;
}
}
}
My Application Code which is the receiver thread for accessing the messages got onto the CAN bus.
DWORD WINAPI Rcv_Msg(LPVOID param){
int *MsgId = new int; //msg id from CAN
int RcvVal; //0 = there is data in the queue; 1 = there is no data
unsigned int uMsgId;
*MsgId = 0;
unsigned char CanData[8];
unsigned int i = 0;
unsigned int j = 0;
unsigned int Startbit = 0;
unsigned int Endbit = 0;
float Offset = 0;
float Resolution = 0;
try {
while(vThread_exit.Rcv_Msg){
RcvVal = receive_data(CanData, MsgId,g_xlPortHandle_global);-------->Here is the error
memcpy(&uMsgId,MsgId,4);
UI64 RawCanData;
if(RcvVal == 0){ //there is data in the queue
switch(uMsgId){ //switch statement that parses the incoming message based ON the message id.
So this program builded successfully and while executing it I am getting the error as
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).
Please help me with this.
Thanks in Advance.
[CODE\]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|