08-11-2009 09:10 AM
Hey Ya'll
I have a dll written in C and when I call the dll from Labview, I get the error:
"Possible reason(s):
LabVIEW: An exception occurred within the external code called by a Call Library Function Node. The exception may have corrupted the LabVIEW memory. Save any work to a new location and restart LabVIEW."
I wrote a driver for my C code and ran it. No exceptions in that code, no errors that I can find.
Also, if I comment-out the C function and effectively send in a blank function to the Call DLL node, the vi finishes with no errors. Therefore I can assume that there are no problems with my inputs to the Call DLL node matching the function prototype in the dll.
Does anyone know of any particular reason that I would get this error of external exceptions when my DLL itself appears to give me no exceptions?
Thanks in advance for any comment.
08-11-2009 09:32 AM
08-11-2009 09:50 AM - edited 08-11-2009 09:52 AM
What is the prototype of the function you're calling?
void Norm(uint8_t *Image, uint32_t width, uint32_t height, uint32_t Nx, uint32_t Ny, double *Norm);
What does your LabVIEW code look like?
Files attached. It simply reads in an image and calls the C library. This vi executes with a test-dummy dll that accepts the same inputs, and outputs a direct copy of the image; therefore, I can assume that the vi is fine and my inputs match the correct types.
Are you using arrays? Is the DLL assuming that the caller allocates memory?
Yes. I initialize two arrays in the calling vi and pass the pointer into the dll. Inside the dll, I dynamically allocate 2 arrays and deallocate them at the end of the function.
I am sure that the arrays are initialized correctly in the code and the correct value and type are passed into the dll. I made sure of this by commenting out the real code, and writing a simple function to copy the original array into the the resulting array. The results were favorable and the array was successfully copied in the dll and the vi finished without errors, and with correct copied values in the resulting array.
Is the DLL allocating memory for things like arrays that doesn't get released?
Yes, I dynamically allocate arrays that are used inside the dll only. These do not get used by my calling vi, and as far as I know, they are effectively deallocated at the end of the function.
Are you using the correct calling convention?
My dll is a .cpp file, but it is written as a C-callable function.