From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error 1097 when passing array from C++ DLL to LabView

I am trying to use a DLL that I created in Visual C++ 2005 Express Edition.  The DLL should output several arrays.  I've attached my source code, header, generated dll, and the LabView code I use.  I always get Error 1097 "LabVIEW:  An exception occurred within the external code called by a Call Library Function Node. The exception may have corrupted LabVIEW's memory. Save any work to a new location and restart LabVIEW."  For the record, the attached code is simplified from what I actually need to doSmiley Wink
I'm using LabView 8.5.  Any advice would be greatly appreciated.
0 Kudos
Message 1 of 55
(17,561 Views)
Well, I've spent another day trying to figure this out with no luck.  I've downloaded the 'GenSort' example:

http://zone.ni.com/devzone/cda/epd/p/id/3183

As well as the Passing a Variety of Data:

http://sine.ni.com/devzone/cda/epd/p/id/1288

I'm sucessful at passing individual numbers (int, double), but I have never been able to pass an array - always with the same error.

I've really tried to follow this second example to get an array out of a C++ created DLL.  After a lot of work, I got to the point where I was looking for another header file ('ansi_c.h').  Now, I've searched for that, but it is apparently in a LabWindows/CVI folder, which I don't have.  This also makes me think I've been wasting my time because I need to use LabView. 
0 Kudos
Message 2 of 55
(17,535 Views)
When I ran your VI using LabVIEW 8.5 I received error 42 which is a generic error.  Is there anything I need to alter on this VI before running it?  I also tried creating a simple program calling your DLL with LabVIEW's Import Shared Library wizard.  I received another error message complaining that the function exported in the library is not declared in the header file that you included.  You can give this a try by going to Tools >> Import >> Shared Library (.dll). 
 
Meghan M.
0 Kudos
Message 3 of 55
(17,512 Views)
I finally got things working.  You need to initialize arrays going into the DLL in LabView (even if they are also initialized in the DLL).  Otherwise, everything was working.  There was a document I missed that helped a lot here:

http://digital.ni.com/public.nsf/allkb/58596F5D41CE8EFB862562AF0074E04C?OpenDocument

Thanks!
Message 4 of 55
(17,496 Views)


@l1k wrote:
I finally got things working.  You need to initialize arrays going into the DLL in LabView (even if they are also initialized in the DLL).  Otherwise, everything was working.  There was a document I missed that helped a lot here:

http://digital.ni.com/public.nsf/allkb/58596F5D41CE8EFB862562AF0074E04C?OpenDocument

Thanks!


It's not the initialization that is important, but the allocation. An array has a certain lenght in memory that is reserved by an allocation. This length can be 0 bytes. When you pass in an empty array (0 bytes) that is fully valid but if the DLL then tries to write into that array (your initialisation or later some data) you write into memory that can and most probably has been allocated by LabVIEW for other things. Et voila you corrupt LabVIEW memory and sooner or later crash.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
Message 5 of 55
(17,314 Views)

Hi guys (and gals if any)

 

I have the same problem (error 1097) when trying to access a function of my DLL, that passes an array. I am sure that everything is alright, as in C++ syntax, header and labview. I think my problem is about memory allocation. I initialize the output array with 0's.

 

What is most peculiar is that just once i got some values in my output array. But that happened only once. 😕

 

What advices you have, if you had this same problem ?

 

Thanks.

 

PS: LabVIEW 2009. Visual C++ 2010. 

0 Kudos
Message 6 of 55
(14,028 Views)

You say that everything is right in terms of allocation, C Syntax, and Call Library Node configuration therefore assume that posting your actual VIs and code won't help. But I have to inform you that the information you give does certainly point to the fact that there is something wrong with one or more of these things.

 

Simply put: LabVIEW hasn't caused errors or crashed on me in quite a number of years now when using the Call Library Node, UNLESS I made an error in one of these mentioned things. So eventhough you believe you did everything right I'm 99.9% sure there still is a problem and you need to investigate that.

 

As to how I debug these things, it all depends. In most cases the DLL is from me so I have the source code and can do source level debugging. If the DLL is not yours you will have to carefully check everything once more, or even better yet put it out to someone knowledgeable. Another pair of eyes always helps, and can discover things you have overlooked over and over again.

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 55
(14,025 Views)

deleted duplicate post

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 55
(14,026 Views)

Hi Rolf, 

 

Thanks for answering. 

 

Well, obviosuly there is an error in my implementation, but I cannot tell where. Everything I did seemed pretty straight forward. I thought there might be a "well-known" issue of the matter. Anyway this is my first experience in DLLs with LabVIEW. 

 

I have attached my files if you have time to take a look over them.

 

Thanks.

0 Kudos
Message 9 of 55
(14,019 Views)

 


@Drakones wrote:

            sumImg[imgWidth*(i-1)+j]= (float)/* sum*/ 50;    


What do you think will the array index into sumImg[imgWidth*(i-1)+j] get when you start i from 0?

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 10 of 55
(14,014 Views)