LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Global variables in DLL being called by TestStand reset to zero or NULL

Solved!
Go to solution

I understand that Global variables in general are a bad idea, but I thought some handles to my XNet CAN interface would be an acceptable use of a global.

nxSessionRef_t g_OutputSessionRef[2] = { 0 , 0 };
nxSessionRef_t g_InputSessionRef [2] = { 0 , 0 };

My system has two DUTs and I can direct CAN traffic based off of socket number.

I would initialize these variables with create session and would get a valid handle.  I could observe them in View Variable value they looked good.

In subsequent calls to the DLL that accessed these values they would be set back to 0.

Its not worth adding a bunch of code snippets - my problem is that these global variables do not keep their values during the life of the DLL.  I have a work around in that for all of my CAN traffic I am passing in an input/output session reference, I basically have moved the global value to TestStand.  To be honest I am now seeing other global variables re-setting to 0.  

My real question is - has anybody else seen this?  Is there some setting that I am missing in the developer environment that would prevent this?  How do I make a global variable be persistent?

If I call these same DLL's from a CVI program designed to test and exercise these DLL's I do not see this behavior.

 

0 Kudos
Message 1 of 3
(1,485 Views)
Solution
Accepted by topic author Schudon99

Hi, 

It seems like you are unloading the DLL somewhere. 

Please check the load/unload options of your steps and the global TestStand setting. 

 

If you have a big sequence file that may be painful. If you put a breakpoint in your DLLMain function, inside DLL_DETACH block, you can detect the point where your DLL gets unloaded.

 

Hope this helps 

 

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 3
(1,446 Views)
Eureka! I was in DLL Hell- I was actually calling two different copies of the DLL. I discovered this because I entered the DLL_DETACH twice! Thanks Much! -don
0 Kudos
Message 3 of 3
(1,430 Views)