LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

dll expects a struct parameter

Hello,
 
I have a movilink.dll, which has a function that expects a struct parameter. The struct looks like this:
 
 
    typedef struct tagSERVICE
      {unsigned char  bService,                 //service to execute
                     fShortCnf;                           //short confirmation enable
      unsigned short wTargetAddress;     //target address or PC-interface
      unsigned short wIndex,                     //Parameter-Index
                     wDataLength;                    //Anzahl PD bei READ..., WRITE.. bzw. Nutzdaten bei SCOPE
      unsigned char  bTeleType;               //0:zykl. sonst: azyklische Telegramme
      union
        {
        long          lDate;                               //standard READ, WRITE
        unsigned char abData[10];               //abData[0]:# of channel with GET_SCOPE
        }Data;                                                //abData[1]:# ob block  with GET_SCOPE

      unsigned short awPA[10],                  //process data to send
                     awPE[10];                           //received process data
      unsigned char far* fpbDataPointer;
      unsigned char      abReserve[10];
      ERRORMSG           Error;
      }SERVICE, far* FPSERVICE;
 
 
And now I have no idea, how i can say to the CLFN to execute the Funktion and give me a Parameter back. The value I expect should be written in the struktureelement "long          lDate; "
 
I tried it with an Array. no success
I made a Cluster that look like the Strukture. Does not work.
 
Has anybody an Idea how I could manage this Problem?
 
 
Best reguards
 
Nico
0 Kudos
Message 1 of 8
(4,816 Views)
Hi Nico,
 
The Problem  is that labview is only capable of standard C-Datatypes and Arrays of those. You can also built some simple structs with clusters (only numeric datatypes).
More complex structs are not supported.
 
The only work arround I know, is to build a wrapper DLL which arranges the data in a format that labview can handle.
 
Hope that helps
0 Kudos
Message 2 of 8
(4,800 Views)

The part I'm not sure about is the Union.  Not quite sure how Labview would handle this.  But here is something to try:

Unsigned Char should be represented in Labview by a U8.  Unsigned short by U16.  For the union, try bundling into a cluster.  First element is U32 for long.  The next element is an array of U8.  Before bundling, convert the array to a cluster using the Array to Cluster function.  Right click on the function and select a cluster size of 10.  Then bundle into the union cluster.  Convert all other arrays to clusters with a size of 10.

Then bundle all other elements including the union/cluster in the same order as the C structure.  It will look like this:

In CLNF, set Type = Adapt to Type and Format = Pointers to Handles.

Give it a shot, it is worth a try.

Message Edited by tbob on 08-24-2006 11:08 AM

- tbob

Inventor of the WORM Global
0 Kudos
Message 3 of 8
(4,798 Views)
I think you'll need to handle the union differently.  The way I recall C unions, the actual storage space needed is the longest single element called out in the union definition.  It isn't a cluster that bundles all the elements together, it's an alias list that tells how to interpret the bytes depending on the alias used to access them.
 
That said, the union appears to want 10 bytes storage, so you need to pass in something using 10 bytes.
 
There are some other potential pitfalls to be aware of.  One general concern has to do with "alignment."  For example, the dll compiler may place separate 1-byte values at memory locations that are at 4-byte multiples, to take advantage of the CPU's native 32-bit addressing.  Or not, depending on various stuff I don't really know much about.  I just remember going through lots of gyrations and permutations trying to get my LV cluster to match a dll bit-for-bit.
 
Good luck, hope the docs are really good!
 
-Kevin P.
ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 4 of 8
(4,789 Views)
Hello tBob,
 
thanks for your reply!
Unfotunately your proposal doesn´t work.
 
@Kevin P.: thanks for your reply too, but I do not understand what you exactly mean.
I must say that I´m working with LabView since some weeks. And I haven´t much experience.
 
I think that Peter is rigth, that I have to build a wrapper DLL for this structure.
 
Is for LabView the big Problem, that the dll code is written in C++?
If yes, could I compile the code in C and the Problem is solved?
Or I have to write a DLL that clutch to the original DLL and wielding the Datatypes for LabView?
 
I´m sorry that I need more help, because the handling with DLL´s isn´t so easy.
 
Thank´s to all.
 
Greetings from Germany
 
Nico
 
 
0 Kudos
Message 5 of 8
(4,745 Views)

Yeah, maybe you just write a wrapper vi.  A very simple approach that's most likely to work would be like this:

Each element of the tagSERVICE struct should be treated as a separate argument passed into the wrapper function.  Inside the function, create a variable of type tagSERVICE and copy the argument values into that variable.  Then call the original function from inside the wrapper.  After the call completes, you *may* need to copy some values back to any arguments that came in as pointers, depending on, well, stuff.

The wrapper function might look something like this:

    void wrapper_function(unsigned char  bService, unsigned char fShortCnf, unsigned short wTargetAddress, unsigned short wIndex, ...     )

You still need to watch out for that "union".

-Kevin P.

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 6 of 8
(4,731 Views)

Hello,

anybody give me some informations about creating a dll.

the pdf using externel code in LabView didn´t help a lot. Are there other tutorials or links about this theme?

 

Thanks in advance and have a nice week...

 

Nico 

0 Kudos
Message 7 of 8
(4,682 Views)

Hi Nico

If you have the source code of your DLL you can build a diffrent interface that incorporates the restrictions of labview.

If you have not, you have have to create a new DLL which calls your DLL inside and split the struct into standard C Datatypes like TBob suggested.

To create a DLL you need a C++ compliler like Visual Studio from MS.

0 Kudos
Message 8 of 8
(4,676 Views)