LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

vc++ dll with multiple data types

Solved!
Go to solution

rolfk wrote:

smercurio_fc wrote:

The Reshape Array function is first used to make sure you have an array that's the same size as the fixed-size array in the target structure. Thus, in your case both arrays would be "reshaped" to 3 since that's the size as defined in the structure. This is then converted to a cluster. This is the "repackaging" part.


Haven't looked at the code but I don't think reshape Array is necessary. The Array To Cluster node has a right click popup dialog that defines the element size of the clusterindependant of the actual size of the incoming array.


I was explaining what the example was doing as I wasn't sure if the OP understood what the example was doing. Good point about being able to eliminate the Reshape Array. Not sure why the creator of the example used that. It's an old example, so perhaps the functions operated differently a long time ago? Can't really see how, though. In fact, looking at the example in more detail, it can be simplified for the string part as well.

 

To ghatz85: I forgot to mention in my explanation that you need to set the cluster size. The example has the cluster size set to 50 since that's how many elements were in the array. The string in that example has 51 (50 characters + null). So for that the Array to Cluster is configured for 51 elemetns.  As I pointed out, the maximum that you can set is 256.

 

 

EDIT: Saw the post that you did that. The setting of the cluster size is absolutely necessary, but I hadn't made that crystal clear. 

Message Edited by smercurio_fc on 01-29-2010 11:01 AM
0 Kudos
Message 21 of 27
(1,461 Views)

If I have an 2D array which includes more than 256 elements, what would i need to use instead of the array to cluster?

0 Kudos
Message 22 of 27
(1,427 Views)

ghatz85 wrote:

If I have an 2D array which includes more than 256 elements, what would i need to use instead of the array to cluster?


You need to write in C a wrapper function that translates the LabVIEW array handle into a C array pointer.

Message Edited by rolfk on 02-03-2010 01:04 AM
Rolf Kalbermatter
My Blog
0 Kudos
Message 23 of 27
(1,417 Views)

extern "C" _declspec(dllexport) int _cdecl AOS_GetData_Array_GH(void *testArray);


typedef struct
 {
  double T1[2];
 } Test_array;


struct MainTestArray
{
 Test_array pTest_array;
};

 

 


_declspec(dllexport) int _cdecl AOS_GetData_Array_GH(void *testArray)

{
 maintestArray = (MainTestArray *) testArray;
 maintestArray->pTest_array.T1[0] = 1.11;
 maintestArray->pTest_array.T1[1] = 1.22;

 return 1;
}

 

 

If my DLL was as simple as this, how would the wrapper DLL look?

0 Kudos
Message 24 of 27
(1,386 Views)

ghatz85 wrote:

extern "C" _declspec(dllexport) int _cdecl AOS_GetData_Array_GH(void *testArray);


typedef struct
 {
  double T1[2];
 } Test_array;


struct MainTestArray
{
 Test_array pTest_array;
};

 

If my DLL was as simple as this, how would the wrapper DLL look?

First your example is syntactically not right! You pass in a void pointer and assign it to an untyped variable. That variable should at least be declared with a type (on the local stack) and since you simply assign it it would be much better to type the parameter itself instead of making it a void pointer and then assign it to an according pointer.

 

And with above in mind there is no wrapper DLL necessary since above declaration is most likely different to what you intended. What you have done could be done much simpler with:

 

typedef struct

 {
  double T1[2];
 } Test_array;

 

extern "C" _declspec(dllexport) int _cdecl AOS_GetData_Array_GH(Test_array *testArray);

{
 testArray->T1[0] = 1.11;
 testArray->T1[1] = 1.22;

 return 1;
}

 

For this no wrapper DLL is necessary since you can simply create a cluster in LabVIEW containing two double precision numbers, configure the parameter as Adapt to Type and connect that cluster to it et voila.

Message Edited by rolfk on 02-04-2010 08:27 PM
Rolf Kalbermatter
My Blog
0 Kudos
Message 25 of 27
(1,381 Views)
typedef struct

 {
  double T1[300];
 } Test_array;

 

extern "C" _declspec(dllexport) int _cdecl AOS_GetData_Array_GH(Test_array *testArray);

{
 testArray->T1[0] = 1.11;
 testArray->T1[1] = 1.22;

''

''

''

 testArray->T1[299] = 10;

 return 1;
}

 

So then what if the code looked something like this with 300 elements as opposed to only 2. Then i would need a wrapper DLL like you mentioned before. The problem here is that my programming skills are pretty much minimal to non existent. Now, going back to my previous question, what would the dll look like if it was written for vc++?

0 Kudos
Message 26 of 27
(1,369 Views)

ghatz85 wrote:
typedef struct

 {
  double T1[300];
 } Test_array;

 

extern "C" _declspec(dllexport) int _cdecl AOS_GetData_Array_GH(Test_array *testArray);

{
 testArray->T1[0] = 1.11;
 testArray->T1[1] = 1.22;

''

''

''

 testArray->T1[299] = 10;

 return 1;
}

 

So then what if the code looked something like this with 300 elements as opposed to only 2. Then i would need a wrapper DLL like you mentioned before. The problem here is that my programming skills are pretty much minimal to non existent. Now, going back to my previous question, what would the dll look like if it was written for vc++?


Personally I think someone who has written such a function should probably be put into a different job where he does not get a chance to write more software, but that is simply my own opinion.

 

Still there wouldn't be any wrapper needed for this academic case. You simply allocate a 300 element double array in LabVIEW and pass it as a C array pointer to the DLL function. Even if the fixed array wouldn't be the only element in the cluster you could still allocate a byte array that is long enough to represent all elements in the cluster pass it as C array pointer to the DLL and on return convert the byte array back into a real LabVIEW cluster by indexing into the correct offset of the byte array and Unflatten the different elements to the actual value or even a double array.

Rolf Kalbermatter
My Blog
0 Kudos
Message 27 of 27
(1,360 Views)