LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

vc++ dll with multiple data types

Solved!
Go to solution

Hi everyone,

 

I'm new to the Labview forums and fairly new to Labview as well.

 

I'm experiencing some errors in my VI and i can't quite figure out what i'm doing wrong. I have a DLL which was written in VC++. There is a function in the DLL which i am calling out in the VI, but the function contains variables which consist of various multiple data types.

 

These are my variables in the VC++ code:

 

typedef struct
 {
  double dDepth;
  double dWidth;
  double dHeight;

  float fVolume;
  float fSurfArea;

  int iGood;
  int iBad;
 } box_t

 

 

Then i have my function which calls out these variables:

 

_declspec(dllexport) int _cdecl ACL_GetData_Array(void *dataArray)
{
 arrayStructure->pArray = (array_t *) dataArray;
 //PrintGeneral("Array pointer set to retrieve data.\n New address to be displayed.");
 //PrintAddr((int)arrayStructure->pArray);
 arrayStructure->pArray->dDepth = 30.3;
 arrayStructure->pArray->dHeight = 40.4;
 arrayStructure->pArray->dWidth = 50.5;
 arrayStructure->pArray->fSurfArea = 60.6f;
 arrayStructure->pArray->fVolume = 70.7f;
 arrayStructure->pArray->iBad = 80;
 arrayStructure->pArray->iGood = 90;
 
 return (int) arrayStructure->pArray;
}

 

 

Now my question is if I just want to read these variables and display them in Labview, how do i do it? So far, i can get the doubles to display correctly but i haven't had any success with the floats and the ints. If this has been posted by another user, i'm sorry for asking the same question. I've been searching for a few days now and haven't come across any useful information.

 

Thanks,

George

0 Kudos
Message 1 of 27
(3,886 Views)

You did not include the subVIs, so we can't check how you've set up the CLFN.

 

I also don't understand what  "arrayStructure" is. Is this a static variable? What's box_t for? That function appears to be expecting an array. An array of what? Inside the function it's being typecast to array_t. What's that?

Message Edited by smercurio_fc on 01-22-2010 01:18 PM
0 Kudos
Message 2 of 27
(3,875 Views)

Oh right. Sorry. I attached an updated zip file with subvi.

 

0 Kudos
Message 3 of 27
(3,871 Views)

Still missing jtTestDLL_init. Please see my edited comment.

 

Based on this latest update, I don't understand why you're passing in an array of 7 doubles. Can you provide more information as to the datatypes used by the DLL?

 

Also, your setup of the CLFN does not match the function prototype. The prototype shows only one parameter, but you're passing 2. 

0 Kudos
Message 4 of 27
(3,865 Views)

I'm sorry for the confusion. I spoke to my colleague and he said that this is the code that i should've posted.

 

*********IN THE HEADER FILE*********

 

typedef struct

                {

                                double dDepth;

                                double dWidth;

                                double dHeight;

                                float fVolume;

                                float fSurfArea;

                                int iGood;

                                int iBad;

                } array_t;

 

struct ArrayStructure

{

                array_t *pArray;

};

 

 

*********IN THE CPP FILE***********

 

array_t *pArrayNew;

 

_declspec(dllexport) int _cdecl initVariables () {

                pArrayNew = new array_t;

                arrayStructure = new ArrayStructure;

                arrayStructure->pArray = pArrayNew;

 

                arrayStructure->pArray->dDepth = 10.0;

                arrayStructure->pArray->dHeight = 20.0;

                arrayStructure->pArray->dWidth = 30.0;

 

                return (int) arrayStructure->pArray;

}

 

_declspec(dllexport) int _cdecl AOS_GetData_Array(void *dataArray) {

                arrayStructure->pArray = (array_t *) dataArray;

                arrayStructure->pArray->dDepth = 30.3;

                arrayStructure->pArray->dHeight = 40.4;

                arrayStructure->pArray->dWidth = 50.5;

                arrayStructure->pArray->fSurfArea = 60.6f;

                arrayStructure->pArray->fVolume = 70.7f;

                arrayStructure->pArray->iBad = 80;

                arrayStructure->pArray->iGood = 90;

               

                return (int) arrayStructure->pArray;

}

 

 

I hope you're able to make more sense with this.  

 

As for your question regarding the 7 doubles, i don't think that is correct. The objective is to extract what has been written in the vc++ code and display it in labview. I figured if the array enters 7 doubles, the first three will be correct since they match up. The next two are floats, and then the last two are ints. 

 

I probably made a mistake with the CLFN as well. Like i said, i'm still new to this stuff and i'm looking for help. Thanks for taking a look.  

0 Kudos
Message 5 of 27
(3,855 Views)
The data structure in the DLL doesn't make much sense to me. I'm assuming the programmer had a good reason for setting it up that way. Can't think of one. Try the attached modification. I cleaned up the code a bit as well.
0 Kudos
Message 6 of 27
(3,836 Views)
One thing that I wanted to point out. It's not clear what the other functions in the DLL do, but if they try to mess around with the memory that was allocated by LabVIEW for that cluster, then it will be in for a surprise. LabVIEW can deallocate that memory as soon as it's no longer being used. Thus, if the DLL is expecting that memory to be around, it will likely cause a crash when it tries to modify it.
0 Kudos
Message 7 of 27
(3,824 Views)

If possible, can you save the modified VI under version 8.5.1? Labview won't let me open the files that you attached to the forum.

 

As far as the data structure in the DLL, the programmer had rearranged the data types to go from largest to smallest.

0 Kudos
Message 8 of 27
(3,794 Views)
Solution
Accepted by topic author ghatz85

ghatz85 wrote:

If possible, can you save the modified VI under version 8.5.1? Labview won't let me open the files that you attached to the forum.


Sorry. For some reason I thought the originals were in LV 2009. Attached is 8.5 version.

 


As far as the data structure in the DLL, the programmer had rearranged the data types to go from largest to smallest.

I was referring to having a structure inside a structure and calling it an "array".

 

 

 

Message 9 of 27
(3,783 Views)

Wow. You nailed that one. Thanks so much for the help.

 

George

0 Kudos
Message 10 of 27
(3,759 Views)