06-28-2011 08:24 AM
General protection fault 001B:0012FC86 error is being displayed while trying to execute my code. While debugging i found this error is got after executing an window message callback. Until it executes the last line of the callback there is no error. The error is got immidiately after executing the callback.
PVICALLBACK OnResponseGlobalEvent(long WParam, long LParam)
{
int ret;char str[50];
ResponseInfo = &ResponseInfo1;
ret = PviGetResponseInfo(WParam, 0, 0, (T_RESPONSE_INFO*)ResponseInfo, sizeof(T_RESPONSE_INFO));
if (ret==0)
{
//ret = PviReadResponse(WParam, 0, 0);
switch(ResponseInfo->nType)
{
case POBJ_EVENT_PVI_CONNECT:
strcpy(str, "Pvi Connected");
ResetTextBox (paneldlg, PANELDLG_txtPviConnStatus, str);
DisplayPanel (paneldlg);
break;
case POBJ_EVENT_PVI_DISCONN:
strcpy(str, "Pvi Not Connected");
ResetTextBox (paneldlg, PANELDLG_txtPviConnStatus,"Pvi Not Connected");
break;
case POBJ_EVENT_PVI_ARRANGE:
break;
}
}
//free(&ResponseInfo);
return 0;
}
Solved! Go to Solution.
06-28-2011 11:21 AM
Hello -
Was it just a mistake, or is that actually the prototype for your callback function? Are you using the function InstallWinMsgCallback? If so, and that is actually your prototype, that could certainly be the source of your problem. The prototype for a WinMsgCallback function *must* be:
Try making that change, and let us know if it resolves things for you.
NickB
National Instruments
06-29-2011 01:39 AM
I am sorry for wrongly mentioning it as a windows message function.
The function is defined in the PviCom.h as shown below.
// simple callback function:
#define SET_PVICALLBACK0xffffffff
typedef void (WINAPI *PVICALLBACK)(WPARAM,LPARAM);
The function that i am using is defined in the .c file as follows
PVICALLBACK OnResponseGlobalEvent(long WParam, long LParam);
The function is called after the user message is replied by the following global event message setup function
PviSetGlobEventMsg (POBJ_EVENT_PVI_CONNECT,(PVICALLBACK) OnResponseGlobalEvent,SET_PVICALLBACK,0);
The OnResponseGlobalEvent function is mentioned in the above message.
Thank you very much for your help.
Regards,
Jay.
06-29-2011 09:31 AM
Hmmm... I'm not at all familar with that API, but it looks like you may have gotten the calling convention confused with the function pointer typedef.
In the PviCom header file, WINAPI is the calling convention, and PVICALLBACK is the type. Presumably, PviSetGlobEventMsg takes a PVICALLBACK function pointer as it's 2nd parameter, but you're passing it something else entirely. The PVICALLBACK function pointer type returns void, but the function you're passing returns a pointer to a function (although you're actually returning 0). This mismatch in return types could cause stack corruption.
Also, the calling convention of your function mostly likely does not match that of the typedef. The typedef specifies that the calling convention of the callback function should be WINAPI (__stdcall when compiling under CVI), but the default calling convention in CVI is __cdecl. This could also be a source of stack corruption.
Considering these things, I would recommend the following changes:
As a general rule, when you pass a function pointer to another function, you should be very wary of any errors or warnings the compiler shows you. If at all possible, I would entirely avoid casting.
NickB
National Instruments
06-30-2011 07:54 AM
Hello Nick,
The solution you provided was helpful in solving the problem. It is a real pleasure communicating with you.
Thank you very much.