RegEdit
Übersicht

![]() |
BtbNBetreff: RegEdit |
![]() Antworten mit Zitat ![]() |
---|---|---|
Code: [AUSKLAPPEN] SuperStrict
Rem bbdoc: RegEdit EndRem Module BtbN.RegEdit ModuleInfo "Version: 1.00" ModuleInfo "BB-Version Author: gman" ModuleInfo "BMX Port by: BtbN" ModuleInfo "License: Public Domain" ?win32 Import BRL.Bank Import BRL.Retro Import "-ladvapi32" Private Extern "win32" Function RegOpenKey:Int(hKeyParent:Int,SubKey$z,phkResult:Byte Ptr)="RegOpenKeyA@12" Function RegCloseKey:Int(hKey:Int)="RegCloseKey@4" Function RegCreateKey:Int(hKeyParent:Int,SubKey$z,phkResult:Byte Ptr)="RegCreateKeyA@12" Function RegDeleteKey:Int(hKeyParent:Int,SubKey$z)="RegDeleteKeyA@8" Function RegSetValue:Int(hKey:Int,ValueName$z,Reserved:Int,nType:Int,Bytes:Byte Ptr,size:Int)="RegSetValueExA@24" Function RegDeleteValue:Int(hKey:Int,ValueName$z)="RegDeleteValueA@8" Function RegEnumKey:Int(hKey:Int,idx:Int,Key:Byte Ptr,size:Int)="RegEnumKeyA@16" Function RegEnumValue:Int(hKey:Int,idx:Int,ValueName:Byte Ptr,NameSize:Byte Ptr,Reserved:Int,nType:Byte Ptr,ValueBytes:Byte Ptr,ValueSize:Byte Ptr)="RegEnumValueA@32" Function RegQueryValueEx:Int(hKey:Int,ValueName$z,Reserved:Int,nType:Byte Ptr,ValueBytes:Byte Ptr,ValueSize:Byte Ptr)="RegQueryValueExA@24" EndExtern Public ' registry roots Rem bbdoc: HKEY_CLASSES_ROOT EndRem Const HKEY_CLASSES_ROOT:Int = -2147483648 Rem bbdoc: HKEY_CURRENT_USER EndRem Const HKEY_CURRENT_USER:Int = -2147483647 Rem bbdoc: HKEY_LOCAL_MACHINE EndRem Const HKEY_LOCAL_MACHINE:Int = -2147483646 Rem bbdoc: HKEY_USERS EndRem Const HKEY_USERS:Int = -2147483645 ' Return value constants Rem bbdoc: REG_ERROR_SUCCESS EndRem Const REG_ERROR_SUCCESS:Int = 0 Rem bbdoc: REG_ERROR_EOF EndRem Const REG_ERROR_EOF:Int = 259 ' no more entries in key ' data types For keys Rem bbdoc: REG_SZ EndRem Const REG_SZ:Int = 1 ' Data String Rem bbdoc: REG_BINARY EndRem Const REG_BINARY:Int = 3 ' Binary Data in any form. Rem bbdoc: REG_DWORD EndRem Const REG_DWORD:Int = 4 ' A 32-bit number. Rem bbdoc: reg_lasterr EndRem Global reg_lasterr:Int = REG_ERROR_SUCCESS Rem bbdoc: Enumerates the keys contained in the passed subkey and returns them as a delimited String in the format:<br>KEY=VALUE|KEY=VALUE|KEY=VALUE EndRem Function reg_enumvalues:String(RegKey:Int,SubKey:String,delim:String="|",types:Int=False) Local cRetVal:String="",key:String="",val:String="" Local keybank:TBank=CreateBank(100),keybanksize:TBank=CreateBank(4),valbank:TBank=CreateBank(100),valbanksize:TBank=CreateBank(4),typebank:TBank=CreateBank(4) Local char:Int=0,nIdx:Int=0,nType:Int=0 ' open the key Local hKey:Int=reg_openkey(RegKey,SubKey:String) If hKey<>-1 ' read in the values Repeat ' init the banks PokeInt(typebank,0,0) PokeInt(valbanksize,0,100) PokeInt(keybanksize,0,100) ' clear out the temp values key:String="" val:String="" If RegEnumValue(hKey,nIdx,BankBuf(keybank),BankBuf(keybanksize),0,BankBuf(typebank),BankBuf(valbank),BankBuf(valbanksize))<>REG_ERROR_EOF nType=PeekInt(typebank,0) ' tack on the delimiter If cRetVal:String<>"" cRetVal:String=cRetVal:String+delim:String EndIf ' build the key name For char=0 To PeekInt(keybanksize,0)-1 If PeekByte(keybank,char)=0 Then Exit key:String=key:String+Chr(PeekByte(keybank,char)) Next Select nType ' read in a String Or binary value Case REG_SZ, REG_BINARY ' build the value For char=0 To PeekInt(valbanksize,0)-1 If PeekByte(valbank,char)=0 Then Exit val:String=val:String+Chr(PeekByte(valbank,char)) Next ' read in an integer Case REG_DWORD val:String=PeekInt(valbank,0) End Select If types cRetVal:String=(cRetVal:String+PeekInt(typebank,0)+"'"+key:String+"="+val:String) Else cRetVal:String=(cRetVal:String+key:String+"="+val:String) EndIf Else Exit EndIf nIdx=nIdx+1 Forever reg_closekey(hKey) EndIf typebank = Null valbank = Null valbanksize = Null keybank = Null keybanksize = Null Return cRetVal:String End Function Rem bbdoc: Enumerates the keys contained in the passed subkey And returns them as a delimited String in the format:<br>KEY|KEY|KEY EndRem Function reg_enumkeys:String(RegKey:Int,SubKey:String,delim:String="|") Local cRetVal:String="" Local keybank:TBank=CreateBank(100) Local nIdx:Int=0,char:Int ' open the key first Local hKey:Int=reg_openkey(RegKey,SubKey:String) If hKey<>-1 Repeat If RegEnumKey(hKey,nIdx,BankBuf(keybank),BankSize(keybank))<>REG_ERROR_EOF ' tack on the delimiter If cRetVal:String<>"" cRetVal:String=cRetVal:String+delim:String EndIf For char=0 To BankSize(keybank)-1 If PeekByte(keybank,char)=0 Then Exit cRetVal:String=cRetVal:String+Chr(PeekByte(keybank,char)) Next Else Exit EndIf nIdx=nIdx+1 Forever reg_closekey(hKey) EndIf keybank = Null Return cRetVal:String End Function Rem bbdoc: Deletes a value from the registry. returns: #True / #False EndRem Function reg_deletevalue:Int(RegKey:Int,SubKey:String,ValueName:String) Local hKey:Int=reg_openkey(RegKey,SubKey:String) Local lRetVal:Int=False If hKey<>-1 Local nRslt:Int=RegDeleteValue(hKey,ValueName:String) If (nRslt=REG_ERROR_SUCCESS) lRetVal=True Else reg_lasterr=nRslt EndIf reg_closekey(hKey) EndIf Return lRetVal End Function Rem bbdoc: Gets a value from the registry And returns it as a string.<br>Will Return the passed Default if the value requested is Not found in the registry. EndRem Function reg_getvalue:String(RegKey:Int,SubKey:String,ValueName:String,Dflt:String="",types:Int=False) Local cRetVal:String=Dflt:String Local hKey:Int=reg_openkey(RegKey,SubKey:String) Local char:Int=0,nType:Int=0 ' open the key If hKey<>-1 Local valbank:TBank=CreateBank(100),valbanksize:TBank=CreateBank(4),typebank:TBank=CreateBank(4) ' init the banks PokeInt(typebank,0,0) PokeInt(valbanksize,0,100) Local nRslt:Int=RegQueryValueEx(hKey,ValueName:String,0,BankBuf(typebank),BankBuf(valbank),BankBuf(valbanksize)) If (nRslt=REG_ERROR_SUCCESS) cRetVal:String="" nType=PeekInt(typebank,0) ' build the value Select nType ' read in a String Or binary value Case REG_SZ, REG_BINARY ' build the value For char=0 To PeekInt(valbanksize,0)-1 If PeekByte(valbank,char)=0 Then Exit cRetVal:String=cRetVal:String+Chr(PeekByte(valbank,char)) Next ' read in an integer Case REG_DWORD cRetVal:String=PeekInt(valbank,0) End Select ' tack on the Type If requested If types cRetVal:String=nType+"'"+cRetVal:String EndIf Else reg_lasterr=nRslt EndIf reg_closekey(hKey) EndIf Return cRetVal:String End Function Rem bbdoc: Sets a value in the registry. defaults To Type String, but can pass REG_DWORD And REG_BINARY. returns: #True / #False EndRem Function reg_setvalue:Int(RegKey:Int,SubKey:String,ValueName:String,Value:String,nType:Int=REG_SZ) Local hKey:Int=reg_openkey(RegKey:Int,SubKey:String) Local lRetVal:Int=False,i:Int If hKey<>-1 Local valbank:TBank ' create a bank To hold the info Select nType Case REG_SZ, REG_BINARY valbank=CreateBank(Len(Value:String)) For i=1 To Len(Value:String) PokeByte(valbank,i-1,Asc(Mid(Value:String,i,1))) Next Case REG_DWORD valbank=CreateBank(4) PokeInt(valbank,0,Int(Value:String)) End Select Local nRslt:Int=RegSetValue(hKey,ValueName:String,0,nType,BankBuf(valbank),BankSize(valbank)) If (nRslt=REG_ERROR_SUCCESS) lRetVal=True Else reg_lasterr=nRslt EndIf reg_closekey(hKey) EndIf Return lRetVal End Function Rem bbdoc: Deletes the passed key from the registry. returns: #True / #False EndRem Function reg_deletekey:Int(RegKey:Int,KeyName:String) reg_lasterr=REG_ERROR_SUCCESS Local nRslt:Int=RegDeleteKey(RegKey,KeyName:String) If nRslt<>REG_ERROR_SUCCESS reg_lasterr=nRslt EndIf Return (nRslt=REG_ERROR_SUCCESS) End Function Rem bbdoc: Returns the registry handle Or -1 If failed. EndRem Function reg_createkey:Int(RegKey:Int,KeyName:String) reg_lasterr=REG_ERROR_SUCCESS Local regbank:TBank=CreateBank(4) Local hKey:Int=-1 Local nRslt:Int=RegCreateKey(RegKey:Int,KeyName:String,BankBuf(regbank)) If (nRslt=REG_ERROR_SUCCESS) hKey=PeekInt(regbank,0) Else reg_lasterr=nRslt EndIf regbank = Null Return hKey End Function Rem bbdoc: Returns the registry handle Or -1 If failed EndRem Function reg_openkey:Int(RegKey:Int,KeyName:String) reg_lasterr=REG_ERROR_SUCCESS Local regbank:TBank=CreateBank(4) Local hKey:Int=-1 Local nRslt:Int=RegOpenKey(RegKey:Int,KeyName:String,BankBuf(regbank)) If (nRslt=REG_ERROR_SUCCESS) hKey=PeekInt(regbank,0) Else reg_lasterr=nRslt EndIf regbank = Null Return hKey End Function Rem bbdoc: Closes the registry key. returns: #True / #False EndRem Function reg_closekey:Int(RegKey:Int) reg_lasterr=REG_ERROR_SUCCESS Local nRslt:Int=RegCloseKey(RegKey) If nRslt<>REG_ERROR_SUCCESS reg_lasterr=nRslt EndIf Return (nRslt=REG_ERROR_SUCCESS) End Function Rem bbdoc: Returns True If the key exists. EndRem Function reg_iskey:Int(RegKey:Int,KeyName:String) Local hKey:Int=reg_openkey(RegKey,KeyName:String) Local lRetVal:Int=False If hKey<>-1 reg_closekey(hKey) lRetVal=True EndIf Return lRetVal End Function ? Dies ist eine BMax Portierung von gman's BB-Userlib für die Registry: http://www.blitzbasic.com/code...?code=1136 Einfach in die Datei *BMax Dir*/mod/BtbN.mod/RegEdit.mod/RegEdit.bmx kopieren, und das Modul kompilieren. dann noch docmods aufrufen, damit die Befehle in Bmax anerkannt werden. Vielen Dank an Suco-X für die Hilfe bei dem blöden Extern! |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group