Cyclothymia Posted July 31, 2008 Report Share Posted July 31, 2008 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 Quote Link to comment
gleichman Posted July 31, 2008 Report Share Posted July 31, 2008 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? Quote Link to comment
Cyclothymia Posted July 31, 2008 Author Report Share Posted July 31, 2008 QUOTE (gleichman @ Jul 30 2008, 01:25 PM) Is the dll in the same directory as your vi? Is the path set correctly in the call library node? Yes, I think so. The VI runs perfectly fine if I merely copy and paste the block diagram into a new VI and save it without modification. Quote Link to comment
Cyclothymia Posted August 7, 2008 Author Report Share Posted August 7, 2008 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. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.