From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

Passing Cluster Containing Strings in C DLL as Struct

Solved!
Go to solution

So like the attached example? This doesn't seem to work. Though I may be missing something.

0 Kudos
Message 11 of 16
(1,952 Views)
Solution
Accepted by topic author KeenanJohnson

Please be more specific than "doesn't work." Do you get an error, bad data, or some other problem?

 

The number of bytes to copy is 4x the array length, because each array element is 4 bytes. You are only allocating enough space for 1/4 of the array elements, and then only copying 1/4 of them.

Message 12 of 16
(1,949 Views)

Ah yes that appears to have solved it. Thanks so much.

 

How did you figure out all of this? Trial and error? The documentation is pretty poor.

0 Kudos
Message 13 of 16
(1,946 Views)

Mostly from reading lots of posts on this forum, especially the ones by RolfK; but also several years of C programming; a little trial and error; and reading the documentation, even though it's sparse.

0 Kudos
Message 14 of 16
(1,941 Views)

Hello I have a similar problem : using Labview 2012 I have to pass a cluster parameter containing numeric values in C DLL developed with Visual C++ 20120 express (that configure serial channels on a Serial Board) as a Struct so defined :

 

struct ChannelInfoEx

{

ViInt16 interfaceType;

ViInt32 baudRate;

ViInt16 numBits;

ViInt16 stopBits;

ViInt16 parity;

ViUInt16 flowControl;

};

 

This parameter is passed to a VI as a AdaptToType with a format Handles by Value

 

All the fields of the struct (except interfacetype the first one) have a shifted values (stopbits has the value for parity numbits for stopbits and so on).

This problem is raised when I have deleted from the first filed of the struct (ViInt16 channelName) and I have tried to define all the fields as ViInt32 and the parameters are passed correctly.

Someone could help me and explain this strange behaviour ?? It's a Labview bug ??

There is a way to avoid to redefine all the fields as ViInt32 in the DLL ??

0 Kudos
Message 15 of 16
(1,747 Views)

Hello Sergin,

 

This link is going to guide you to a pdf called: Using external code in LabVIEW, there is a complete chapter on how to use external Dlls in LabVIEW

 

 

http://www.ni.com/pdf/manuals/370109a.pdf

Randy @Rscd27@
0 Kudos
Message 16 of 16
(1,733 Views)