To download NI software, including the products shown below, visit ni.com/downloads.
Overview
This example demonstrates how to programmatically set your PCs system time by calling the SetSystemTIme function from the Windows' kernel32.dll.
Description
In kernel32.dll, there is a function called SetSystemTime defined as follows:
BOOL WINAPI SetSystemTime(
_In_ const SYSTEMTIME *lpSystemTime
);
There are two main things to notice about this function.
As such, how do we configure the Call Library Function Node VI such that the dll call behaves appropriately?
When configuring the return type you will notice that there is no boolean data type option. In this case we will set the return type as Signe 8-bit as shown in the image below. The boolean is returned in the signed bit of the number and can be indexed out.
What about the data type SYSTEMTIME? What is this? Reading the documentation for the function on MSDN shows that SYSTEMTIME is a Typed Defined Structure defined as follows:
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME;
We can implement a structure in LabVIEW with a cluster. In the definition each part of the system time is stored as a WORD or Unsigned 16-bit integer. Thus we can implement this paramter in LabVIEW by creating a cluster of eight U16 controls. Now that we know what to pass in from LabVIEW how do we configure the Call Library node? In LabVIEW we pass clusters/structures as an Adapt To Type datatype. Leaving the default as Handles By Value will meet our needs.
Requirements
Steps to Implement or Execute Code
Additional Information or References
VI Block Diagram
**This document has been updated to meet the current required format for the NI Code Exchange.**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.