﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
4106	_WinAPI_RegEnumKey() Returns Incorrect @extended Value	tukangusil7@…		"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)

{{{#!autoit lineno=1 marks=8
Func _WinAPI_RegEnumKey($hKey, $iIndex)
    Local $tLastWriteTime = DllStructCreate($tagFILETIME)
    Local $aCall = DllCall('advapi32.dll', 'long', 'RegEnumKeyExW', 'ulong_ptr', $hKey, 'dword', $iIndex, 'wstr', '', _
            'dword*', 256, 'dword', 0, 'ptr', 0, 'ptr', 0, 'ptr', DllStructGetPtr($tLastWriteTime))
    If @error Then Return SetError(@error, @extended, '')
    If $aCall[0] Then Return SetError(10, $aCall[0], '')

    Return SetExtended($aCall[8], $aCall[3])  ; Wrong: $aCall[8] is lpftLastWriteTime pointer
EndFunc   ;==>_WinAPI_RegEnumKey
}}}

== Proposed Fix

{{{#!autoit lineno=1 marks=8
Func _WinAPI_RegEnumKey($hKey, $iIndex)
	Local $tLastWriteTime = DllStructCreate($tagFILETIME)
	Local $aCall = DllCall('advapi32.dll', 'long', 'RegEnumKeyExW', 'ulong_ptr', $hKey, 'dword', $iIndex, 'wstr', '', _
			'dword*', 256, 'dword', 0, 'ptr', 0, 'ptr', 0, 'ptr', DllStructGetPtr($tLastWriteTime))
	If @error Then Return SetError(@error, @extended, '')
	If $aCall[0] Then Return SetError(10, $aCall[0], '')

	Return SetExtended($aCall[4], $aCall[3])  ; $aCall[4] is lpcchName (character count)
EndFunc   ;==>_WinAPI_RegEnumKey
}}}
"	Bug	new		AutoIt	3.3.18.0	None		_WinAPI_RegEnumKey	
