Jump to content

Calling DLL from Call Lib Func node only works for new program (?!)


Recommended Posts

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 --> [see attached image]

It worked fine, as long as the file was still open, so I saved and quit.

HOWEVER, when I restarted LabVIEW again and ran the same program, it stopped working 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 copy and paste the program contents into a new file, save and run.

It worked once again, as long as the file was open.

I also made a C++ program that calls the DLL, and it works fine, regardless of when it was called.

I have a feeling that it might have to do with memory allocation, but I'm not sure.

Any help would be appreciated.

ps. I am not permitted to upload .cpp, .dev, or .dll files for some reason.

#include "getpathdll.h"#include // C++ includes#include //#include    // already included in getpathdll.h// OpenCV includes#include #include //#include //#include #define LoThresh 160#define HiThresh 160#define ApertureSize 3 // 1,3,5,7extern "C"{DLLIMPORT int cvApplyCanny();       
BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
                       DWORD reason        /* Reason this function is being called. */ ,
                       LPVOID reserved     /* Not used. */ )
{
    return TRUE;
}


    DLLIMPORT int cvApplyCanny ()
    {                  
    //Initialize error log? also line 93

    char* LoadImagePath = fnGetPath("original", "01-11089.jpg");
	IplImage* iniImage = cvLoadImage(LoadImagePath);

	//Create a temporary and final image
	IplImage* grayImage = cvCreateImage(cvSize(iniImage->width, iniImage->height), IPL_DEPTH_8U, 1);
	IplImage* edgeImage = cvCreateImage(cvSize(iniImage->width, iniImage->height), IPL_DEPTH_8U, 1);

	//Convert image to grayscale
	cvCvtColor(iniImage, grayImage, CV_BGR2GRAY);

	//Perform Canny edge detection
	cCanny(grayImage, edgeImage, LoThresh, HiThresh, ApertureSize);

    char* SaveImagePath = fnGetPath("canny", "YayWorked.jpg");
	cvSaveImage(SaveImagePath, edgeImage);

	// Destroy the images
	cvReleaseImage(&iniImage);
	cvReleaseImage(&grayImage);
	cvReleaseImage(&edgeImage);

}
#undef DLLIMPORT

Link to comment

QUOTE (Cyclothymia @ Jul 30 2008, 08:15 AM)

It worked fine, as long as the file was still open, so I saved and quit.

HOWEVER, when I restarted LabVIEW again and ran the same program, it stopped working and generated error 1097:

Is the dll in the same directory as your vi? Is the path set correctly in the call library node?

Link to comment

UPDATE [6th August 2008]:

I have yet to solve the problem, or even gotten any idea of how to solve it.

I tried rewriting the code with Visual C++ (instead of Dev-CPP) and then running the DLL through

LabVIEW using the Visual Studio "attach to process" debugging method;

it ran through without any complications for multiple times.

Again, this generated DLL:

1) Works fine for any amount of times with a new VI with a Call Lib Func node is written for the DLL

2) Stops working once LabVIEW.exe is closed, reopened, and the VI is run again.

3) will work again if the code is copy-and-pasted into a new blank VI without changing any properties;

as long as LabVIEW.exe is not closed and reopened, it will still work.

4) This cycle of errors is repeatable and no different from the one generated by the Dev-CPP compiler.

I would very, very much appreciate any new input to this problem, even some indication that LabVIEW

has a bug or something, or erroneous IDE settings, or a comment on my n00bishness... ANYTHING at all.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.