LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

calling dll functions with structs containing strings

Hello together,
I want to call several dll functions from LabVIEW, most of them are containing structs with strings or similar.

the  functions are documented like this:
RFC_HANDLE RfcOpen(RFC_OPTIONS * options)

the structs are documented like this:
typedef struct {
    char * destination;
    RFC_MODE mode;
    void * connopt;
    char * client;
    char * user;
    char * password;
    char * language;
    int trace;
} RFC_OPTIONS;

enum RFC_MODE {
    RFC_MODE_R3ONLY,
    RFC_MODE_CPIC,
    RFC_MODE_VERSION_3,
    RFC_MODE_PARAMETER,
    RFC_MODE_CPIC_EXT
};

I tried to manage this by using the option "adapt to type" in the call library function window and connected a cluster with the typedef contents.
But that didn´t work, LabVIEW crashed or mentions "an exception occured within the external code...."
What do you think was my fault?
See the attached VI.

Martin



0 Kudos
Message 1 of 2
(2,195 Views)

Hello Martin.

By right-clicking on the "Call Library Function Node" and selecting "Create .c File ..." you can get some C code that points out how data is passed from LabVIEW to the DLL.

Focus on the strings: They are not passed by a pointer to the string. The internal representation of a LabVIEW string contains the string length in the first four bytes (representing an Int32) followed by the string bytes. LabVIEW passes the pointer to that Int32 to the DLL and expects that the DLL knows that the string starts 4 bytes later.
This makes your DLL call crash.

As solution to this requires that you create a (LabVIEW compatible) wrapper for the DLL you want to call.

Using Structures in a DLL with Clusters in LabVIEW also deals with how to pass LabVIEW clusters to a DLL. Also look at the LabVIEW help topic "How LabVIEW stores data in memory"

Best regards, Guenter

 

Message 2 of 2
(2,182 Views)