#4106 closed Bug (No Bug)
_WinAPI_RegEnumKey() Returns Incorrect @extended Value
| Reported by: | Owned by: | ||
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | 3.3.18.0 | Severity: | None |
| Keywords: | _WinAPI_RegEnumKey | Cc: |
Description
The current implementation of _WinAPI_RegEnumKey() returns $aCall[8] as @extended, which corresponds to the pointer to the FILETIME structure (lpftLastWriteTime), not the character count. The correct index for the character count (lpcchName output parameter) is $aCall[4].
This causes @extended to contain a large memory address (e.g., 1234567890) instead of a small integer representing the string length.
Current Code (Buggy)
| Line | |
|---|---|
| 1 | Func _WinAPI_RegEnumKey($hKey, $iIndex) |
| 2 | Local $tLastWriteTime = DllStructCreate($tagFILETIME) |
| 3 | Local $aCall = DllCall('advapi32.dll', 'long', 'RegEnumKeyExW', 'ulong_ptr', $hKey, 'dword', $iIndex, 'wstr', '', _ |
| 4 | 'dword*', 256, 'dword', 0, 'ptr', 0, 'ptr', 0, 'ptr', DllStructGetPtr($tLastWriteTime)) |
| 5 | If @error Then Return SetError(@error, @extended, '') |
| 6 | If $aCall[0] Then Return SetError(10, $aCall[0], '') |
| 7 | |
| 8 | Return SetExtended($aCall[8], $aCall[3]) ; Wrong: $aCall[8] is lpftLastWriteTime pointer |
| 9 | EndFunc ;==>_WinAPI_RegEnumKey |
Proposed Fix
| Line | |
|---|---|
| 1 | Func _WinAPI_RegEnumKey($hKey, $iIndex) |
| 2 | Local $tLastWriteTime = DllStructCreate($tagFILETIME) |
| 3 | Local $aCall = DllCall('advapi32.dll', 'long', 'RegEnumKeyExW', 'ulong_ptr', $hKey, 'dword', $iIndex, 'wstr', '', _ |
| 4 | 'dword*', 256, 'dword', 0, 'ptr', 0, 'ptr', 0, 'ptr', DllStructGetPtr($tLastWriteTime)) |
| 5 | If @error Then Return SetError(@error, @extended, '') |
| 6 | If $aCall[0] Then Return SetError(10, $aCall[0], '') |
| 7 | |
| 8 | Return SetExtended($aCall[4], $aCall[3]) ; $aCall[4] is lpcchName (character count) |
| 9 | EndFunc ;==>_WinAPI_RegEnumKey |
Attachments (1)
Change History (6)
by , on Jul 12, 2026 at 1:11:33 PM
| Attachment: | Test_WinAPI_RegEnumKey.au3 added |
|---|
Test_WinAPI_RegEnumKey
comment:4 by , on Jul 13, 2026 at 11:26:45 AM
Replying to Jpm:
Where it is ?
There is an attachment in the post above on the righthand side. :-)
https://www.autoitscript.com/trac/autoit/attachment/ticket/4106/Test_WinAPI_RegEnumKey.au3
comment:5 by , on Jul 13, 2026 at 6:03:24 PM
| Resolution: | → No Bug |
|---|---|
| Status: | new → closed |
As I said the example from the Help file is correct
The function is not suppose to return a count but a struct to the lasttime
No Bug

See the example which is ok to retrieve the last time
for me no bug