![]() |
|
Pointers and Structures |
|
| About |
This PRG source code compares two different approaches for filling and accessing the TIME_ZONE_INFORMATION structure. The structure is filled in with data by the GetTimeZoneInformation() API function. The TIME_ZONE_INFORMATION structure is declared as follows:
Approach #1 uses YukonBIN.dll. It relies on declaring the API function as DLLFUNCTION in PRG code. Approach #2 uses YukonSTC.dll and accesses the structure without declaring anything in PRG code. Both approaches for accessing the TIME_ZONE_INFORMATION structure outline the incremental design of The YUKON Project. With YukonBIN.dll, you can program the second approach by yourself, thus saving money. With YukonSTC.dll, you gain access to more than 2000 structures of the Windows platform SDK built into The YUKON Project, thus saving time. The YUKON Project is designed to save you the most precious thing: It is either Time or Money. |
| Approach #1 |
// FILE: GetTimeZoneInformation1.prg // Copyright (c) Hannes Ziegler, 2008 // This file is published as Open Source for The YUKON Project (www.knowleXbase.com) #include "Dll.ch" #include "YukonBIN.ch" PROCEDURE Main // Create a pointer for 172 bytes of memory (initial value for all bytes is Chr(0)) LOCAL oCPointer := CPointer():new( , 172 ) // Pass the pointer to an API function GetTimeZoneInformation( oCPointer:ptr ) // 172 bytes are filled in by the API function for the TIME_ZONE_INFORMATION structure // Read the Wide Character string at offset 4 ? ConvToOemCp( W2Char( oCPointer:ptr + 4 ) ) // "StandardName" member // Read the Wide Character string at offset 88 ? ConvToOemCp( W2Char( oCPointer:ptr + 88 ) ) // "DaylightName" member // Read 4 bytes of information at offset 0 and convert to LONG ? Bin2L( oCPointer:read( 0, 4 ) ) // "Bias" member // Read 4 bytes of information at offset 168 and convert to LONG ? Bin2L( oCPointer:read( 168, 4 ) ) // "DaylightBias" member oCPointer:destroy() RETURN DLLFUNCTION GetTimeZoneInformation( pTZI ) USING STDCALL FROM Kernel32 |
| Approach #2 |
// FILE: GetTimeZoneInformation2.prg // Copyright (c) Hannes Ziegler, 2008 // This file is published as Open Source for The YUKON Project (www.knowleXbase.com) // Do the same as above using a structure object and a NameSpace #include "YukonSTC.ch" PROCEDURE Main // create the structure object LOCAL oTZI := StructLoad( "TIME_ZONE_INFORMATION" ) // pass the structure object to the API function via NameSpace KERNEL32.GetTimeZoneInformation( oTZI ) // Query the structure object using Windows platform SDK member names ? ConvToOemCP( oTZI:StandardName ) // "StandardName" member ? ConvToOemCP( oTZI:DaylightName ) // "DaylightName" member ? oTZI:bias // "Bias" member ? oTZI:DaylightBias // "DaylightBias" member // cleanup memory StructFree( @oTZI ) RETURN |
| Copyright © Dr. Hannes Ziegler 2008 | |