LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass a structure (not a pointer to the structure) to a dll

I am using Call Library Function, trying to pass a structure to the function in dll.

 

The function is like this:

        int DllFunc(int a, DLLSTRUCT dllstruct);

 

The structure is simply like this:

    typedef _DLLSTRUCT

    {

       int a;

       int b;

       char c;

    } DLLSTRUCT;

 

I created a cluster like the structure, and tried to use "Adapt to Type", "Handles by Value" to pass the structure to the dll function. LabVIEW crashes.

I guess it actually passes in the pointer to the structure, not the structure.

 

Is there a way to pass in the structure to DLL?

Otherwise I will have to create a wrapper function.

 

Thanks for any input.

0 Kudos
Message 1 of 9
(2,908 Views)
Using a cluster is the correct method, and Adapt to Type should be what you use. Take a look at the "Call DLL" example that ships with LabVIEW. What datatypes did you use for the individual cluster elements?
0 Kudos
Message 2 of 9
(2,888 Views)

Thanks. 

I took a look at the "Call Dll" example, the Cluster example has Function Prototype: void CLUSTERSimple(TD1 *input, TD1 *output); in which input is a structure pointer.

 

The Function I am trying to access is passing in the structure, Not the pointer, such as void CLUSTERSimple_str(TD1 input, TD1 *output); can I do this?

 

0 Kudos
Message 3 of 9
(2,879 Views)
Unfortunately, clusters are always passed by reference, not by value.
0 Kudos
Message 4 of 9
(2,858 Views)

Then I think I will have to use a wrapper function.

Thank you.

0 Kudos
Message 5 of 9
(2,850 Views)

Your cluster is 72 bits, right?

 

Shame it's not 64 or less because you could then trick LV into wrapping your data in a U64 (using the cast function) scalar and pass that (willingly telling LV to pass it as something other than it actually is).

 

I don't see a way of passing more than 64 bits by value with the call library node.

 

Looks like you really need a wrapper DLL.

 

Shane.

Message 6 of 9
(2,826 Views)

Yes, it is more than 64bits.

But thanks for the trick.

0 Kudos
Message 7 of 9
(2,810 Views)

How could i do this Wrapper function?

Respectively how could i handle with the following problem in C#


i have this in my header-file of the SharedLib.h

typedef struct {
	LVBoolean status;
	int32_t code;
	LStrHandle source;
	} TD1;


void __cdecl IP_Supply_GET_Current(TD1 *FehlerEingang, LVBoolean *Start, 
	TD1 *FehlerAusgang, LVBoolean *End);

long __cdecl LVDLLStatus(char *errStr, int errStrLen, void *module);

 and try to make a project with this rudimentary start:

 

namespace IP_GET_Current
{

 /**   interface TestInterface
    {
      Boolean status{
        get;
        set;
      }

    } **/
    public class Class1 /**: TestInterface**/
    {
        [DllImport("C:\\SharedLib.dll", EntryPoint = "IP_Supply_GET_Current", ExactSpelling = false)];

        static extern unsafe void IP_Supply_GET_Current(Int32 code, Boolean Start, Boolean End, Int32 code);

        public struct TD1{
            Boolean status;
            Int32 code;

        }

        Boolean Start;
        Boolean End;

        
        public Main()
        {
            IP_Supply_GET_Current(3,true,true,2);
        }
        
       }
}

 

How can i start to solve the problemß

 

Thanks

0 Kudos
Message 8 of 9
(2,511 Views)

Arphex,

 

I am not sure what you are asking for.  Are you looking for help writing the wrapper?  Are you trying to write a dll to call from LabVIEW?

 

If this is specifically related to C# or .NET, you may find better resources at the MSDN forums, since this is a primarily LabVIEW forum.  However, if you can help us understand a little bit better what you need help with, we may be able to help you as well.

 

Thanks, and good luck!

Drew T.
Camber Ridge, LLC.
0 Kudos
Message 9 of 9
(2,487 Views)