LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
nasa2grlv

NumericArrayResize

Status: Declined
Programming bug issue. There is a workaround listed in the comments though.

Does anybody else have issues with NumericArrayResize?

I am running windows 7 x64, 32 bit labview, and creating a 32 bit dll.  There is a bug on the packing of the structure for doubles. I had to add a #pragma pack(1) to the code for my configuration.

I modified an example off the NI website/help as follows.  The example originally uses uint8, change the code for doubles and it did not work.  I think the "extcode.h" has improper #if/#defines for checking system configuration.

#include "extcode.h"

#pragma pack(1)

 

typedef struct {

long dimSize;

double elt[1];

} TD2;

typedef TD2 **TD2Hdl;

 

_declspec (dllexport) long sizeToTen(TD2Hdl array);

_declspec (dllexport) long sizeToTen(TD2Hdl array)

{

  double * temp;

    MgErr error;

    error = NumericArrayResize(fD, 1, (UHandle *)(&array), 10*sizeof(double));

   (*array)->dimSize = 10;

   temp = (*array)->elt;

   temp[3] = (double)1;

   temp[7] = (double)2;

   temp[9] = 255;

   return error;

}

 

7 Comments
RavensFan
Knight of NI

This thread is for new Ideas about improving LabVIEW.  Your message certainly isn't that.  You say you are using LabVIEW, but yet you are talking about some C code.

 

Perhaps you want the LabWindows forum?

nasa2grlv
Member

It is for calling external c-code in LABVIEW using LABVIEW's Call Library Function Node LABVIEW Block. Fixing LABVIEW is improving LABVIEW.

Mr.Mike
NI Employee (retired)

Could you clarify what eactly you think is wrong and why you think the packing is wrong? 

-- Mike
nasa2grlv
Member

First off I am using VS2010 and labview 2010 32bit with a 32 bit dll to be called by Labview on 64bit Windows 7.

My release project defines are from the project properties:

 

WIN32;NDEBUG;_WINDOWS;_USRDLL;AES_UNWRAP_EXPORTS;%(PreprocessorDefinitions)

 

The results of the above code without the #pragma pack(1) as displayed on a front panel of a VI is

0, 0, 0, 0, 5.29981E-315, 0, 0, 0, 5.30499E-315, 0

 

 

Chris_W1
Member

So, let me see if I understand:  you're saying that LabVIEW is wrong to not include the #pragma pack, as you have done manually, in the example?  Yes, I agree with you.

 

If I remember correctly, LabVIEW introduced the lv_prolog.h and lv_epilog.h headers in LV 2010 for this reason.  An easy way to see these headers in use is to right-click on a Call Library Node and choose "Create C File".

 

Here's the header I get from doing that on my machine:

 

/* Call Library source file */

 

#include "extcode.h"

 

/* lv_prolog.h and lv_epilog.h set up the correct alignment for LabVIEW data. */
#include "lv_prolog.h"

 

/* Typedefs */

 

typedef struct {
   int32_t dimSize;
   double elt[1];
   } TD1;
typedef TD1 **TD1Hdl;

 

#include "lv_epilog.h"

 

int32_t sizeToTen(TD1Hdl array);

 

int32_t sizeToTen(TD1Hdl array)
{

 

 /* Insert code here */

 

}

nasa2grlv
Member

Thanks for your help, I will try constructing my cfile that way.  We'll it is their function, if you tell a function to do something it should work without any headaches.

G-Money
NI Employee (retired)
Status changed to: Declined
Programming bug issue. There is a workaround listed in the comments though.