From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does my dll fail to exit properly after an unsuccessful attempt to construct a CNiFieldPointNetworkModule?

I am attempting to create a DLL using the FieldPoint API for MeasurementStudio. In my initial testing, I find that the application that is calling my DLL will hang when trying to unload the DLL. This only happens after an unsuccessful call to the constructor for CNiFieldPointNetworkModule. Is there a way that I can exit gracefully after such an error. (I am trapping the exception and calling its Delete member function before returning an error code to the calling app when the construction error occurrs.)

Thanks in advance.

Wayne Steinhour
0 Kudos
Message 1 of 9
(3,655 Views)
You haven't given that much information. Why and how does the constructor fail? Does it only happen if you use a DLL, or can you get it to work with out using a dll? You can use trace statements to see where the dll hangs.
Can you reproduce it with a small dll? If so, could you post it here?
0 Kudos
Message 2 of 9
(3,655 Views)
Carl,

Thanks for taking the time to respond to my question.
A bit more information:

When the constructor fails, it throws a "CNiFieldPointConnectionException". The error code usually indicates a timeout but somtimes a bad address. (I am doing some very preliminary testing. There is no fieldpoint module at the IP address that I am using.)

I have not tried to make an executable, since my end goal is a DLL.

The dll hangs in CWinApp::ExitInstance(). It only hangs after I have made an unsuccessful attempt to construct a CNiFieldPointNetworkModule. (If I just load and unload the dll without attempting the construction, there is not problem.)

I suspect that the culprit may be an incorrect version of Datasockets. My PC has version 4.0(367). T
he docs say that I need version 4.0.3.378, but I have not been able to locate it on NI's web site.

If you have any ideas, or can tell me where to get the datasocket upgrade, I will appreciate it.

Thanks.
0 Kudos
Message 3 of 9
(3,655 Views)
Wayne:

I've written a little DLL/EXE tester to try and reproduce this, but I haven't been successful. I've attached the project below if you'd like to take a look at it. I have a compatible version of DataSocket, so perhaps that is why mine works and your is having trouble. You'll definitely want to get the newest version of DataSocket if you plan to use the FieldPoint C++ API; even if the old version hasn't caused this problem, it will probably cause others.

I also haven't been able to locate the right version of DataSocket on our website. I'm talking to some of the web folks to make sure it's found and put in an intuitive place. I'll post to this thread as soon as I track down the right version. Thanks for pointing this out.


Hope this helps,
-- Chris
0 Kudos
Message 4 of 9
(3,655 Views)
Wayne:

The FieldPoint for Measurement Studio module should install the correct version of DataSocket. Have you installed anything after installing FieldPoint for Measurement Studio? You may try repairing or reinstalling the module to see if this corrects the problem.

-- Chris
0 Kudos
Message 5 of 9
(3,655 Views)
Chris,

Thanks for the input. I tried out your tester. It exits cleanly on my PC, so the Datasocket version must not be the problem.

I am including the source code for my DLL. If you would have the time to look it over, I would appreciate it. (The ZIP file also includes a simple LV vi that calls the DLL. I will not be actually calling the DLL from LV, but it is an easy way to test it.)

I suspect that I am leaving out something simple, but I cannot seem to find it.

Thanks for your help.
Wayne
0 Kudos
Message 6 of 9
(3,655 Views)
Wayne:

Your code looks fine to me. In fact, when I added an EXE project to your workspace to test it, it runs fine and exists gracefully. Perhaps we are testing the DLL differently? Can you try running my test on your machine and let me know what happens?

-- Chris
0 Kudos
Message 7 of 9
(3,655 Views)
Chris,

Your EXE, does work fine on my PC. The difficulty seems to be in the mechanism used to laod the dll. I modified your EXE to call "LoadLibrary" and "GetProcAddress" to get a function pointer to the GetNetworkModulePosition function. When I called "FreeLibrary", it hangs. Apparently, there is some difference in the call to DllMain when you use load-time vs run-time dynamic linking. I don't understand this, so I will have to investigate further. What do you think is going on here? (I am attaching the two files of yours that I changed in case my description is not clear.)

Wayne
Download All
0 Kudos
Message 8 of 9
(3,655 Views)
I've spoken to Wayne offline and we have solved this particular problem. If anyone else experiences a problem like this concerning the Measurement Studio FieldPoint C++ API, please contact National Instruments Technical Support.

-- Chris W, NI
0 Kudos
Message 9 of 9
(3,655 Views)