LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

cvi dll crashes when called second time from c++

i am running cvi 6.0 and visual studio 6.0 and have developed an application that needs to load a cvi dll and execute an exported function.

the problem that i'm having is that the 2nd time that the exported function is called, my application terminates. running this through the cvi debugger indicates that "the program has caused a 'General Protection' fault at some locale. in the vc++ debugger, an access violation is raised.

the peculiar thing is that by changing the size of stack variables (either on the cvi side or the c++ side) the problem goes away.

i've included a very pared down example of what's happening. notice that there is no actual work being done in the cvi code (the only call is in
an if ( 0 ) condition)!

thanks in advance!
Download All
0 Kudos
Message 1 of 4
(3,149 Views)
oops, i attached the wrong header . . . please disregard that file and use the following header, thanks!
0 Kudos
Message 2 of 4
(3,149 Views)
Sir,
I cannot directly determine the nature of this error. I'm not sure that there is an error at all. I built your dll incorrectly from the CVI side the first time I built it. Then I was able to get an access violation error to report. When I built the dll correctly the second time, I was able to get the application to run correctly. It reports a few warnings, two being that the handles to the threads you created were not closed out. This isn't a big deal, being the creation is within the main(). Also there was a warning that suggests you use a FreeLibrary call as well within your if else statement. I recommend putting that in.
I would look at the project window of CVI under the BUILD >> TARGET SETTINGS. You will see a "Change" button near the bott
om for the Exports. Make sure you have one of the last two selected under the drag down menu. These are "symbols Marked for Export" or "Include File and Marked Symbols". You have to select one of these two because you have not prototyped the function in your header, rather you used DLLEXPORT __stdcall PS_Open in your source file.

Daniel McChane
Application Engineer
National Instruments
0 Kudos
Message 3 of 4
(3,149 Views)
daniel,

thanks for your input. i'm guessing that when you build the dll the first time, you did not have the target settings set to export the functions.

this is definitely not the case on my machine. actually, i've been able to get the application to run properly under windows xp; however, the app bombs under windows nt, again on the second call.

as far as the freelibrary call, this is something that i do in my real application, but wanted to pare this down in the example.

the output that i get on my machine is as follows:
open call succeeded for PS1

and then program execution halts. as i said earlier, in the debugger, it's clear that some sort of access violation occurs on the second call.

thanks again! any additional information is defi
nitely appreciated.
0 Kudos
Message 4 of 4
(3,149 Views)