LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling dll function that has struct that consist of union as input parameter

Version:1.0 StartHTML:000000235 EndHTML:000002791 StartFragment:000001962 EndFragment:000002759 StartSelection:000001962 EndSelection:000002759 SourceURL:https://forums.ni.com/t5/forums/editpage/board-id/170/message-id/1095110

I have function "myFunction" in dll that is defined like this:

DLL_EXPORT unsigned long myFunction(void * pHandle, myComplexParameter configuration);

 

myComplexParameter is struct that is defined in another .h file and it is defined as:

struct myComplexParameter
{
  myCommunicationCode communication_code;      // This is struct
  myConfig config_code;    // This is struct
}

myConfig is another struct that is defined in the sam .h file as:

struct myConfig
{
	MA_Frequency ma_clock; // union
};

So MA_Frequency is:

union MA_Frequency
{
	uint32_t frequency_hz;								enum frequency;	
};

 

Is it possible to call this function from labview using call library function node? How can C++ dll code be redefined to be used in labview?

 

0 Kudos
Message 1 of 3
(2,194 Views)

It's not easily visible as I thought at first that your union only consists of one element which would be pretty useless. But in C an union is as large as the largest block inside the union is, so unless you have a very strange C compiler that does something pretty unexpected for enums, the union is in fact simply the size of the uint32_t. The enum is occupying the same memory location as the uint32_t.

 

In respect to your last question, please explain in more detail. It's not clear what you are asking.

Rolf Kalbermatter
My Blog
Message 2 of 3
(2,165 Views)

@Skoda3 wrote:

How can C++ dll code be redefined to be used in labview? 


If this question refers to how to call a C++ class from LabVIEW through the Call Library Node the answer is to write a wrapper DLL in C++, which must export standard C functions for every class method you want to call and in additiona to that a constructor and destructor function.

 

Take a look at this recently reactivated LabVIEW Wiki page which explains the principle.

 

The canonical start page for this is: https://labviewwiki.org/

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 3
(2,152 Views)