LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Call library function node only works with new VI

This is my first time making a DLL and programming in C++, so please bear with me if I had made some fundamental mistakes.
I have made a DLL that reads images and performs Canny edge detection using the OpenCV libraries.
So I made a very simple LabVIEW program to test it (just a lib node with inputs and one output).
It worked fine, so I saved and quit. HOWEVER, when I restarted LabVIEW again and ran the same program,
it almost stopped working when the signal reached the Node and generated Error 1097:

----
Error 1097 occurred in Call Library Function Node in Canny.dll:
An exception occurred within the external code called by the Call Library Function Node.
The exception may have corrupted LabVIEW's memory.
Save any work to a new location and restart LabVIEW.
----

The only way I got it to work again was to:
1) copy and paste the program contents into a new file without any other modification, save and run.
2) change the DLL within the node configurations to any other DLL; this could also mean an exact copy of the DLL.
It worked once again, as long as LabVIEW.exe was not restarted; i.e. I could close the VI and reopen it
as many time as I wanted and it still works, but when I shut LabVIEW off, restart it and reopen the same VI, it generates the above error.


I made a C++ program that calls the DLL, and it works fine, regardless of when and how many times it was called.
I also tried debugging it in Visual Studio and that worked fine too, regardless of when and how many times it was called.

Because of this, coupled with the fact that DLL works any amount of times in LabVIEW in a new VI, convinces me that
the settings of the node and the programming within the DLL code is correct (code is still available on request, nothing propietary).

I have a feeling that it might have to do with how LabVIEW deals with its own memory preallocation/pointer validation
(apart from what is done in the DLL), or even a bug in LabVIEW, but I'm not sure.

Any help would be appreciated. Many thanks in advance.

0 Kudos
Message 1 of 12
(3,326 Views)
It seems you're not the only one trying to play around with the OpenCV library. Since you don't have anything proprietary, please post your suspect VI and we can try to take a look at it.

P.S. Don't forget to post your DLL as well, though you will need to put it into a ZIP archive in order to post it. Please provide header files so we can see the function prototypes. Or, if you just want to post the code for the DLL that's fine also.


Message Edited by smercurio_fc on 08-06-2008 10:42 AM
0 Kudos
Message 2 of 12
(3,322 Views)
Here is the VI, with the C++ file, header file and a settings file (settings.ini).

The ini file needs to be put in the same folder as the generated DLL.
It contains the folder that holds the images that need to be processed,
and the folder it outputs images too.

Eventually this will be replaced by a live feed from a camera,
but that shouldn't change the fact that I'm getting this weird error.

I also posted the problem on the LAVA forums   >> HERE <<
0 Kudos
Message 3 of 12
(3,304 Views)
It seems that you're using Visual C++ 2005. I think that's your problem. When I compiled your code using Visual C++ 6.0 (after needing to make a few minor changes due to the library differences), I had no problem calling the DLL. I never got that error. To be honest, I don't have a lot of experience using Visual C++ 2005. The DLLs that I've created were done using 6.0. Anything else I've used .NET. You may want to check the Knowledge Base and this forum for any "gotchas" with Visual C++ 2005.
0 Kudos
Message 4 of 12
(3,292 Views)
Actually, I first used Dev-CPP, but the error above happened.
Then I switched to Visual Studio 2008 to try debugging it using "attach to process", which worked perfectly during debug.
However, when I ran the same program using the DLL generated by VS, the error was still present.
0 Kudos
Message 5 of 12
(3,290 Views)
Well, I have even less experience with Visual Studio 2008 since I don't have it. Smiley Very Happy

As I said, when I compiled the code you provided with Visual Studio 6.0 it worked just fine (after making those minor changes). I don't really know what else to tell you.
0 Kudos
Message 6 of 12
(3,287 Views)
Just making sure: are you sure you turned LabVIEW.exe off, restart it and run that same program again?
My VI worked the first time I created it too -- after restarting LabVIEW,exe, it stopped working.

Just to clarify:
I am using LabVIEW 8.5,
Visual C++ 2008 of Visual Studio ver.9.0.21022.8 RTM,
Dev-CPP 4.9.9.2
0 Kudos
Message 7 of 12
(3,285 Views)
Can you also specify the minor changes to made to the libraries?
Sorry to be picky, but you have to understand that this has been baffling me for almost 2 weeks now.
0 Kudos
Message 8 of 12
(3,284 Views)
Yes, I restarted LabVIEW each time. The mods I had to make were :
  • fopen_s -> fopen
  • sprintf_s -> sprintf
  • moved #include <iostream> to be called before #include "getpathdll.h" (I think this is VC++ 6.0 specific.)
  • in fnGetPath had to declare i on its own line, as you cannot redeclare it in the second for-loop (again, a VC++ 6.0 issue).
Attached is the complete VC++ 6.0 project that I used, including the VI, in case it helps.


Message Edited by smercurio_fc on 08-06-2008 03:46 PM
0 Kudos
Message 9 of 12
(3,264 Views)
Thanks for all your help.

On a whim, I tried making a LabVIEW 7.1 program and called the same DLL... it worked. (!?)
This is very agonizing, but at least I got it to work consistently on a LabVIEW interface.


Message Edited by M. Shahini on 08-06-2008 03:51 PM
0 Kudos
Message 10 of 12
(3,260 Views)