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: 

During DLL selction I always get the error 1097

Solved!
Go to solution

Hi!

 

I would like to include a DLL in my labview programm. I am afraid, I get always the error 1097.

 

-------------------------------

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.

--------------------------------

 

 

How can I comitted an 2D-Array from labview to dll?

The size of the arrays are 246 * 310. See c++ code below!!!

 

------------------------------------------------

 

#include "stdafx.h"
#include<cmath>
const int DIM1 =246;
const int DIM2 =310;

BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
      )
{
    return TRUE;
}

 

_declspec (dllexport) double WINAPI correlation(double temp[DIM1][DIM2], double candidate[DIM1][DIM2], long rows, long column)  // both 2D Arrays are 246 * 310  Is this correct?
{
 double sum_quad_temp = 0.0;
 double sum_quad_candidate = 0.0;
 double sum_numerator=0.0;

 double denominator = 0.0;
 double result = 0.0;

 double numerator[DIM1][DIM2];
 double quad_temp[DIM1][DIM2];
 double quad_candidate[DIM1][DIM2];
 
 for (int a=0; a<=rows; a++)
 {
  for (int b=0; b<=column; b++)
  {
   // to do

  }
 }
 
 for (int i=0; i<=rows; i++)
 {
  for (int j=0; j<=column; j++)
  {   
   //to do

  }
 }
 
 // to do

 

 return (result); // the return type  is numeric (8 byte double)
}

 

 

0 Kudos
Message 1 of 6
(3,311 Views)

MarcQ wrote:
both 2D Arrays are 246 * 310  Is this correct?

It really depends how you mean that. If you try to simply pass a LabVIEW 2D array unchanged to the DLL you will have a real problem. LabVIEW arrays are NEVER equal to C arrays.

 

Your C array is in declared as a 2D array but in C multidimensional arrays declared as in your case are in fact simply a one dimensional memoryblocks whose size is the total multiplication of all dimensions. So how can you pass an array from LabVIEW to the DLL in this way?

 

Basically LabVIEW already comes with everything necessary. You simply configure the parameter as Array of the right type and the according number of dimensions (2) and the Array Format as Array Data Pointer.

 

Now maybe you have done so already and in that case you have made the standard error of all LabVIEW Call Library Node beginners. LabVIEW can allocate memory automatically in its diagrams when needed, but has absolutely no idea how much memory your DLL function would need and there is simply no way for LabVIEW to know. The C function in the DLL however does not usually (and only could do so if explicitedly written in such a way and using native LabVIEW datatypes) allocate memory in a way that LabVIEW can use it and normally relies on the caller to allocate any buffers needed for its parameters. You can do that in LabVIEW by using an Initiliaze Array node with the correct dimensional sizes.

 

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 6
(3,291 Views)

Hi Rolf!

 

Thanks for your quick reply!

 

 

When I initilize an Array with the right size in LabView, how can comitted it into the DLL?

 

Maybe like this??

 

_declspec (dllexport) double WINAPI correlation(double** temp[][dim2], double** candidate[][dim2], double size_temp, double size_candidate, long rows, long column)

{

//to do

}

 

 
The red script is the initialization of the dimensions for two arrays.

The blue script comitted the size of both 2D-arrays.

 

Thanks a lot in advance

0 Kudos
Message 3 of 6
(3,269 Views)
Solution
Accepted by MarcQ

No no! Just use the double name[][] declaration. In C

 

double name[dim1][dim2] is equivalent to double name[dim1 * dim2] and for a function parameter also the same as double *name (obviously the last does not apply for variable declarations itself as the first two will allocate a buffer in memory while the last only allocates a pointer, but as far as parameter passing all three are simply a pointer to a memory area, and I believe the first two are only valid for parameters in C++ or maybe C99) so as you can see it is simply a one dimensional array of elements. In LabVIEW you work with your two dimensional array and configure the Call Library Node accordingly and to pass the array as C Array Pointer. LabVIEW then will take care to pass the pointer to the actual array data to the DLL function.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 6
(3,265 Views)

Hi MarcQ,

 

I have found 2 links, which may be interesting for your problem.

1)  Why Does LabVIEW Crash When I Call My DLL?
     http://digital.ni.com/public.nsf/allkb/58596F5D41CE8EFB862562AF0074E04C?OpenDocument

     (general information about possible mistakes when using dll calls in LabVIEW)

 

2)  Passing a Variety of Data Types from DLL to LabVIEW
     http://zone.ni.com/devzone/cda/epd/p/id/1288

     (LabVIEW and C code to show the right use of dll calls)

I hope the links can help you solve your problem or at least getting an idea of how to find a workaround.

 

Sincerely yours

Gregor

0 Kudos
Message 5 of 6
(3,263 Views)

Hi Rolf and Gregor!

 

Thanks a l ot !!!

 

Now it works!!!

 

take care

Message 6 of 6
(3,257 Views)