' Registry Demo — read/write via DECLARE
#COMPILE EXE
#DIM ALL

DECLARE FUNCTION RegOpenKeyEx LIB "ADVAPI32.DLL" ALIAS "RegOpenKeyExA" (BYVAL hKey AS LONG, BYVAL lpSubKey AS ASCIIZ, BYVAL ulOptions AS LONG, BYVAL samDesired AS LONG, BYREF phkResult AS LONG) AS LONG
DECLARE FUNCTION RegCloseKey LIB "ADVAPI32.DLL" (BYVAL hKey AS LONG) AS LONG

%HKEY_CURRENT_USER = &H80000001
%KEY_READ = &H20019
%ERROR_SUCCESS = 0

FUNCTION PBMAIN() AS LONG
    LOCAL hKey  AS LONG
    LOCAL result  AS LONG
    result = RegOpenKeyEx(%HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion", 0, %KEY_READ, hKey)
    IF result = %ERROR_SUCCESS THEN
        PRINT "Registry key opened successfully"
        RegCloseKey(hKey)
    ELSE
        PRINT "Failed to open registry key"
    END IF
    FUNCTION = 0
END FUNCTION
