Jump to content

Binary to DLLStruct


Recommended Posts

I'd like to convert a Binary variable, such as returned by RegRead() for a REG_BINARY entry, into a DLLStruct. I can do it by using a bunch of BinaryMid() and DllStructSetData() calls, but I'm hoping there is a way to simply copy the entire structure from a Binary variable to an appropriately formatted DLLStruct.

I'm looking for an elegant way to convert a registry Time Zone Info field (e.g. HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Eastern Standard Time\TZI) into data that can be passed to _Date_Time_SetTimeZoneInformation().


Link to comment
Share on other sites

You can create the DLLStruct first. Then create a second DLLStruct as a byte-array on the pointer of the first struct and set the binary data to it. Now you can free the second struct again (does not free memory since it wasn't allocated by DLLStructCreate) and the data can be accessed from the first struct.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Thanks for the pointer.

Here is the code in case anyone else can use it...

SetTimeZone("Eastern Standard Time")

; Set the time zone
Func SetTimeZone($name)
    ; The Registry key of the Time Zones collection
    Const $tzKey = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\"
    ; The Registry TZI field structure
    Const $tagTZI = "align 2; long Bias; long StdBias; long DayBias; BYTE StdDate[16]; BYTE DayDate[16]"        

    ; Create the data structures
    $tzi = DllStructCreate($tagTZI)
    $stdDate = DllStructCreate($tagSYSTEMTIME)
    $dayDate = DllStructCreate($tagSYSTEMTIME)

    ; Read the registry data
    $binTzi = RegRead($tzKey & $name, "TZI")
    $dayName = RegRead($tzKey & $name, "Dlt")
    $stdName = RegRead($tzKey & $name, "Std")
    ; Copy the binary TZI data to the TZI structure
    $tmp = DllStructCreate("BYTE[44]", DllStructGetPtr($tzi))
    DllStructSetData($tmp, 1, $binTzi)
    ; Get the integer data
    $bias = DllStructGetData($tzi, "Bias")
    $stdBias = DllStructGetData($tzi, "StdBias")
    $dayBias = DllStructGetData($tzi, "DayBias")
    ; Get the SYSTEMTIME data
    $tmp = DllStructCreate("BYTE[16]", DllStructGetPtr($stdDate))
    DllStructSetData($tmp, 1, DllStructGetData($tzi, "StdDate"))
    $tmp = DllStructCreate("BYTE[16]", DllStructGetPtr($dayDate))
    DllStructSetData($tmp, 1, DllStructGetData($tzi, "DayDate"))
    $tmp = 0

    ; Set the current time zone
    _Date_Time_SetTimeZoneInformation($bias, $stdName, $stdDate, $stdBias, $dayName, $dayDate, $dayBias)
Link to comment
Share on other sites

  • 2 months later...

Thanks for the pointer.

Here is the code in case anyone else can use it...

Thanks very much! I avoided to reinvent the wheel for the usage of _Date_Time_SetTimeZoneInformation() function!

With trancexx' and your function I was able to write a script that can change the timezone on Windows Server 2008!



Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...