j'ai besoin d'inscrire une clé dans le registre, pour déclarer un type de fichier, j'utilise la fonction de la droopy lib :
Code : Tout sélectionner
;{ registre
; ecrire une chaine dans le registre
;###########
; CODE de la DROOPY LIB
;###########
Structure OneByte
a.b
EndStructure
; Convertit une chaine de caractères héxadécimale en valeur décimale stockée dans un entier long
ProcedureDLL Hex2Dec(HexNumber.s)
*buf = AllocateMemory(StringByteLength(hexnumber, #PB_UTF8)+1);we need to make the string utf8 for when compiled as unicode
;edit 10/12/2008 changed the above line to account for the null written by the pokes below
PokeS(*buf, HexNumber, -1, #PB_UTF8)
*t.OneByte = *buf;@HexNumber
Result.l = 0
While *t\a <> 0
If *t\a >= '0' And *t\a <= '9'
Result = (Result << 4) + (*t\a - 48)
ElseIf *t\a >= 'A' And *t\a <= 'F'
Result = (Result << 4) + (*t\a - 55)
ElseIf *t\a >= 'a' And *t\a <= 'f'
Result = (Result << 4) + (*t\a - 87)
Else
Result = (Result << 4) + (*t\a - 55)
EndIf
*t + 1
Wend
FreeMemory(*buf)
ProcedureReturn Result
EndProcedure
Procedure RegConvertRegKeyToTopKey(Key.s)
topKey.s=StringField(Key,1,"\")
topKey=UCase(topKey)
Select topKey
Case "HKEY_CLASSES_ROOT"
retour=#HKEY_CLASSES_ROOT
Case "HKEY_CURRENT_USER"
retour=#HKEY_CURRENT_USER
Case "HKEY_LOCAL_MACHINE"
retour=#HKEY_LOCAL_MACHINE
Case "HKEY_USERS"
retour=#HKEY_USERS
Case "HKEY_CURRENT_CONFIG"
retour=#HKEY_CURRENT_CONFIG
EndSelect
ProcedureReturn retour
EndProcedure
Procedure.s RegConvertRegKeyToKeyName(Key.s)
PositionSlash=FindString(Key,"\",1)
retour.s=Right(Key,(Len(Key)-PositionSlash))
ProcedureReturn retour
EndProcedure
ProcedureDLL RegSetValue(Key.s, ValueName.s, Value.s, Type, ComputerName.s) ; OK
; Return 1 if success / 0 if fail
topKey=RegConvertRegKeyToTopKey(Key)
KeyName.s=RegConvertRegKeyToKeyName(Key)
lpData.s
If Left(KeyName, 1) = "\"
KeyName = Right(KeyName, Len(KeyName) - 1)
EndIf
If ComputerName = "."
GetHandle = RegOpenKeyEx_(topKey, KeyName, 0, #KEY_ALL_ACCESS, @hKey)
Else
lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
GetHandle = RegOpenKeyEx_(lhRemoteRegistry, KeyName, 0, #KEY_ALL_ACCESS, @hKey)
EndIf
If GetHandle = #ERROR_SUCCESS
lpcbData = 255
lpData = Space(255)
Select Type
Case #REG_EXPAND_SZ
GetHandle = RegSetValueEx_(hKey, ValueName, 0, #REG_EXPAND_SZ, @Value, StringByteLength(Value) + 1)
Case #REG_SZ
GetHandle = RegSetValueEx_(hKey, ValueName, 0, #REG_SZ, @Value, StringByteLength(Value) + 1)
Case #REG_DWORD
lValue = Val(Value)
GetHandle = RegSetValueEx_(hKey, ValueName, 0, #REG_DWORD, @lValue, 4)
Case #REG_BINARY
LenBuffer=Len(Value)/2
*RegBuffer=AllocateMemory(LenBuffer)
For n=0 To LenBuffer-1
OctetHexa.s=Mid(Value,(n*2)+1,2)
Octet=Hex2Dec(OctetHexa)
PokeB(*RegBuffer+n,Octet)
Next
GetHandle= RegSetValueEx_(hKey,ValueName,0,#REG_BINARY,*RegBuffer,LenBuffer)
FreeMemory(*RegBuffer)
EndSelect
RegCloseKey_(hKey)
ergebnis = 1
ProcedureReturn ergebnis
Else
RegCloseKey_(hKey)
ergebnis = 0
ProcedureReturn ergebnis
EndIf
EndProcedure
;###########
;}
Code : Tout sélectionner
res = RegSetValue("HKEY_CLASSES_ROOT\.mgwa", "", "SCMangwa", #REG_SZ, ".")
Debug res
Donc ça ne fonctionne pas.