LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI 2017 The program has caused a 'General Protection' fault.

Function A calls function B which calls a function in a DLL.

The DLL function returns to function B.

When Function B tries to execute its return statement, I receive the GP message.

 

I am using the debugger to step through the source code instructions so I know that the message appears at the return.

I have commented-out everything between the call to the DLL function and the return.

The problem does not occur when I skip over the DLL function call.

The address where the fault occurs is not within the address space of any module listed in the Modules window.

 

Can anybody give me further suggestions of what to try.

Thank you.

0 Kudos
Message 1 of 10
(4,109 Views)

Sounds like you've got it pretty well narrowed down to that DLL. Any word on what the DLL does or where it came from? Is it something you have the source code for?

 

Additionally, screenshots of your error(s) are always helpful.

 

-Sam

Sam R.
0 Kudos
Message 2 of 10
(4,064 Views)

The DLL is a 1553 device driver that I have the code for. It is built using MS Visual Studio.

 

For debugging this, I modified this function to be only "{return -42;}", so it should not be causing trouble from the source code level.

Not that they were called yet, but I eliminated all warnings in the DLL by replacing calls to strcmp & sprint with strcmp_s & sprint_s.

This is the first function called in the DLL after it is loaded.

We are replacing the target machine from XP to Win10 so I'm rebuilding the existing (working) software and replacing the drivers with new versions.

0 Kudos
Message 3 of 10
(4,062 Views)

Is the calling convention (e.g. __stdcall) explicitly given in the function's signature?

-----------------------
/* Nothing past this point should fail if the code is working as intended */
0 Kudos
Message 4 of 10
(4,038 Views)

The function is declared as int __declspec(dllexport) InitModule(unsigned short int a, unsigned short b);

0 Kudos
Message 5 of 10
(4,034 Views)

It sounds to me like the issue we're seeing may be specific to the DLL that's being called. Are there other similar DLLs that you call in your code that work without tripping this memory fault? 

 

Sam R.
0 Kudos
Message 6 of 10
(4,013 Views)

At this point, I think I should provide more details

 

The system was built in Win 7 with CVI 2009 for an XP box and has been running for years.

We are now upgrading EVERYTHING to Win 10: replacing 1553 card & driver and upgrading to CVI 2017.

I get a General Protection fault when initializing the new 1553 driver.

I was successful in getting past the initialization when using CVI 2017 with old driver and untouched code
The DLL came from the vendor as the driver for the 1553 card. We did successfully try merging it into another program that was built with CVI 2009.
We built the DLL with VS 2012.
I am using the debugger to step through the source code instructions so I know that the message appears at the first function return AFTER the DLL initialization returns. (This will be clearer after looking at the code.
I have commented-out everything between the call to the DLL function and the return.
The problem does not occur when I skip over the DLL function call.
According to the message displayed when the GP fault occurs, the address where the fault occurs is not within the address space of any module listed in the Modules window.

 

The relevant code looks like this:
// Inside main.c

Int (*initFunc)(unsigned short devicenum, unsigned short modnum);

 

void loadAdrs(){
HMODULE Module_ID = LoadLibrary("x.dll"):
initFunc = (void*)GetProcAddress(Module_ID, "DLL_Init_Func");
}

 

void bar(){
int status = (*initFunc)(2, 4);  //executes DLL call as expected return retval;
}//throws a General Protection fault when debugger steps over this bracket


void foo(){
loadAdrs();
bar();
whatever; // according to debugger, execution does not reach this statemant
}

 

int main() {
foo();
}


// Inside seperate DLL
Int __declspec(dllexport)  DLL_Init_Func(unsigned short devicenum, unsigned short modnum){
return -42; //returns some value
}

 

As a test, I tried moving the dll call to inside loadAdrs and then inside foo. In both cases, I got the GP when the function returns to the next level up

0 Kudos
Message 7 of 10
(3,994 Views)

Please try this:

 

// Inside main.c

Int (__stdcall *initFunc)(unsigned short devicenum, unsigned short modnum);

 

// Inside seperate DLL
Int __declspec(dllexport)  __stdcall DLL_Init_Func(unsigned short devicenum, unsigned short modnum)

 

-----------------------
/* Nothing past this point should fail if the code is working as intended */
0 Kudos
Message 8 of 10
(3,981 Views)

no difference - still hits the GP fault. Thanks.

0 Kudos
Message 9 of 10
(3,974 Views)

I can see the same symptom using CVI 2017 and SQL Toolkit 2.3 on a Windows 10 Machine.

"The program has caused a 'General Protection' fault  at 0x0065E68A"

 

Works fine if I compile the program in CVI2013 SP2.

0 Kudos
Message 10 of 10
(3,776 Views)