LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use structure pointer with « Call Library Function node » in LabVIEW

I use GetTimeZoneInformation from kernel32.dll. It definition is :

DWORD GetTimeZoneInformation( LPTIME_ZONE_INFORMATION lpTimeZoneInformation );

Where

lpTimeZoneInformation
[out] Pointer to a TIME_ZONE_INFORMATION structure to receive the current time-zone parameters.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/gettimezoneinformation...

I don't know how to set this parameter with my cluster based on the TIME_ZONE_INFORMATION structure.

Your help will be appreciate

Thanks

INKSPEC
0 Kudos
Message 1 of 2
(3,041 Views)


@INKSPEC wrote:
I use GetTimeZoneInformation from kernel32.dll. It definition is :

DWORD GetTimeZoneInformation( LPTIME_ZONE_INFORMATION lpTimeZoneInformation );

Where

lpTimeZoneInformation
[out] Pointer to a TIME_ZONE_INFORMATION structure to receive the current time-zone parameters.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/gettimezoneinformation...

I don't know how to set this parameter with my cluster based on the TIME_ZONE_INFORMATION structure.

Your help will be appreciate

Thanks

INKSPEC




If creating a wrapper DLL which does the conversion for you is not an option (I think it won't since that would require C programming and if you knew C programming you wouldn't ask this here) then you will have to create a byte array of appropriate length and just configure the Call Library Node to pass this array as an Array of unsigned bytes and as C pointer.

On return you will have to copy out the interesting data at the right position.

First the length of this structure would be:

typedef struct _TIME_ZONE_INFORMATION {
LONG Bias; 4
WCHAR StandardName[32]; 32 * 2
SYSTEMTIME StandardDate; 8 * 2
LONG StandardBias; 4
WCHAR DaylightName[32]; 32 * 2
SYSTEMTIME DaylightDate; 8 * 2
LONG DaylightBias; 4
} TIME_ZONE_INFORMATION

Total 172 bytes

Now the fun part will be to actually get out the information. There are a number of difficulties.

First the strings are 16 bit Unicode so if you are interested in them you will have to call a different Windows API function WideCharToMultiByte function to convert the 16bit Unicode string into an ASCII string. For this part there has been a post here:

http://forums.ni.com/ni/board/message?board.id=170&message.id=123821&requireLogin=False

For the LONG values you would pick 4 bytes at the appropriate offset from the array through the Array Subset function and then typecast it into an int32 and pass that through the Swap Bytes and Swap Words functions to reverse the LabVIEW Big Endian byte swapping in the Typecast function.

The SYSTEMTIME is a structure with eight 2 byte integers so it would be best to use Array Subset again to extract 16 bytes at the correct offset, typecast this into a cluster with eight int16 numerics and pass it through Swap Bytes too.

You see accessing such API functions in LabVIEW directly can get easily quite a mess and that is the reason why creating a wrapper DLL to convert properly between LabVIEW datatypes and C datatypes gets soon the easier solution if you need to interface with more than one or two functions taking such complicated data structures.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 2 of 2
(3,032 Views)