WinApi Registry Funktionen.

Übersicht BlitzMax, BlitzMax NG Allgemein

Neue Antwort erstellen

BtbN

Betreff: WinApi Registry Funktionen.

BeitragMi, Dez 28, 2005 14:58
Antworten mit Zitat
Benutzer-Profile anzeigen
Zitat:
Building regedit
Linking:regedit.exe
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0x1b3): undefined reference to `RegEnumValueA'
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0x428): undefined reference to `RegEnumKeyA'
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0x562): undefined reference to `RegDeleteValueA'
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0x6cb): undefined reference to `RegQueryValueExA'
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0x999): undefined reference to `RegSetValueExA'
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0x9fd): undefined reference to `RegDeleteKeyA'
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0xa90): undefined reference to `RegCreateKeyA'
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0xb45): undefined reference to `RegOpenKeyA'
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0xbab): undefined reference to `RegCloseKeyA'
Build Error: Failed to link C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/regedit.exe
Process complete


Code: [AUSKLAPPEN]
Extern "win32"
   Function RegFlushKey:Long(hKey:Int)="RegFlushKeyA"
   Function RegOpenKey:Long(hKeyParent:Int,SubKey$z,phkResult:Byte Ptr)="RegOpenKeyA"
   Function RegCloseKey:Long(hKey:Int)="RegCloseKeyA"
   Function RegCreateKey:Long(hKeyParent:Int,SubKey$z,phkResult:Byte Ptr)="RegCreateKeyA"
   Function RegDeleteKey:Long(hKeyParent:Int,SubKey$z)="RegDeleteKeyA"
   Function RegSetValueEx:Long(hKey:Int,ValueName$z,Reserved:Int,nType:Int,Bytes:Byte Ptr,size:Int)="RegSetValueExA"
   Function RegDeleteValue:Long(hKey:Int,ValueName$z)="RegDeleteValueA"
   Function RegEnumKey:Long(hKey:Int,idx:Int,Key:Byte Ptr,size:Int)="RegEnumKeyA"
   Function RegEnumValue:Long(hKey:Int,idx:Int,ValueName:Byte Ptr,NameSize:Byte Ptr,Reserved:Int,nType:Byte Ptr,ValueBytes:Byte Ptr,ValueSize:Byte Ptr)="RegEnumValueA"
   Function RegQueryValueEx:Long(hKey:Int,ValueName$z,Reserved:Int,nType:Byte Ptr,ValueBytes:Byte Ptr,ValueSize:Byte Ptr)="RegQueryValueExA"
EndExtern

' registry roots
Const HKEY_CLASSES_ROOT:Int      = -2147483648
Const HKEY_CURRENT_USER:Int      = -2147483647
Const HKEY_LOCAL_MACHINE:Int   = -2147483646
Const HKEY_USERS:Int         = -2147483645

' Return value constants
Const REG_ERROR_SUCCESS:Int    = 0
Const REG_ERROR_EOF:Int         = 259     ' no more entries in key

' data types For keys
Const REG_SZ:Int            = 1      ' Data String
Const REG_BINARY:Int         = 3      ' Binary Data in any form.
Const REG_DWORD:Int            = 4    ' A 32-bit number.

' Global Var holding last error #
Global reg_lasterr:Int      = REG_ERROR_SUCCESS

?win32

' enumerates the keys contained in the passed subkey And returns them as a delimited String in
' the format: KEY=VALUE|KEY=VALUE|KEY=VALUE
Function reg_enumvalues:String(RegKey:Int,SubKey:String,delim:String="|",types=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=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

' enumerates the keys contained in the passed subkey And returns them as a delimited String in
' the format: KEY|KEY|KEY
Function reg_enumkeys:String(RegKey:Int,SubKey:String,delim:String="|")
   Local cRetVal:String=""
   Local keybank=CreateBank(100)
   Local nIdx=0

   ' open the key first   
   Local hKey=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

' deletes a value from the registry.  returns True/False.
Function reg_deletevalue:Int(RegKey:Int,SubKey:String,ValueName:String)
   Local hKey=reg_openkey(RegKey,SubKey:String)
   Local lRetVal=False
   If hKey<>-1
      Local nRslt=RegDeleteValue(hKey,ValueName:String)      
      If (nRslt=REG_ERROR_SUCCESS)
         lRetVal=True
      Else
         reg_lasterr=nRslt
      EndIf
      reg_closekey(hKey)
   EndIf
   Return lRetVal
End Function

' gets a value from the registry And returns it as a string.  will Return the passed Default
' If the value requested is Not found in the registry.
Function reg_getvalue:String(RegKey:Int,SubKey:String,ValueName:String,Dflt:String="",types=False)
   Local cRetVal:String=Dflt:String
   Local hKey=reg_openkey(RegKey,SubKey:String)
   Local char=0,nType=0
   
   ' open the key
   If hKey<>-1
      Local valbank=CreateBank(100),valbanksize=CreateBank(4),typebank=CreateBank(4)
   
      ' init the banks
      PokeInt(typebank,0,0)
      PokeInt(valbanksize,0,100)
   
      Local nRslt=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

' sets a value in the registry.  defaults To Type String, but can pass REG_DWORD And REG_BINARY.
' returns True/False.
Function reg_setvalue:Int(RegKey:Int,SubKey:String,ValueName:String,Value:String,nType=REG_SZ)
   Local hKey=reg_openkey(RegKey:Int,SubKey:String)
   Local lRetVal=False
   If hKey<>-1
      Local valbank
      
      ' 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=RegSetValueEx(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

' deletes the passed key from the registry.  returns True/False.
Function reg_deletekey:Int(RegKey:Int,KeyName:String)
   reg_lasterr=REG_ERROR_SUCCESS
   Local nRslt=RegDeleteKey(RegKey,KeyName:String)
   
   If nRslt<>REG_ERROR_SUCCESS
      reg_lasterr=nRslt
   EndIf
   
   Return (nRslt=REG_ERROR_SUCCESS)
End Function

' returns the registry handle Or -1 If failed.
Function reg_createkey:Int(RegKey:Int,KeyName:String)
   reg_lasterr=REG_ERROR_SUCCESS
   Local regbank=CreateBank(4)
   Local hKey=-1

   Local nRslt=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

' returns the registry handle Or -1 If failed
Function reg_openkey:Int(RegKey:Int,KeyName:String)
   reg_lasterr=REG_ERROR_SUCCESS
   Local regbank=CreateBank(4)
   Local hKey=-1

   Local nRslt=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

' closes the registry key.  returns True/False.
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

' returns True If the key exists
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

?


Kapier ich nicht den Fehler, bitte Hilfe ^^
Ja, das ist ein Versuch, die BB RegFunks nach Bmax zu portieren.
Und ja, das hab ich ausm Englischen Codearchiv.

TheShadow

Moderator

BeitragMi, Dez 28, 2005 15:51
Antworten mit Zitat
Benutzer-Profile anzeigen
hm... hab nur extern code kompiliert und es geht...

versuch mal so:

extern "Win32"
Function RegFlushKeyA:Long(hKey:Int)
...
endextern


also ohne ="xyz" am ende
AMD64 3500+ | GeForce6600GT 128MB | 1GB DDR | WinXPsp2

BtbN

BeitragMi, Dez 28, 2005 16:01
Antworten mit Zitat
Benutzer-Profile anzeigen
Wenn ich nur den Extern-Code kompilieren, geht es, ja.
aber wenn ich den Rest dabei habe, geht es nicht!
Woran kann das liegen?

Edit:

Habs ma geändert, neuer Code:
Code: [AUSKLAPPEN]
Extern "Win32"
   Function RegOpenKeyA:Long(hKeyParent:Int,SubKey$z,phkResult:Byte Ptr)
   Function RegCloseKeyA:Long(hKey:Int)
   Function RegCreateKeyA:Long(hKeyParent:Int,SubKey$z,phkResult:Byte Ptr)
   Function RegDeleteKeyA:Long(hKeyParent:Int,SubKey$z)
   Function RegSetValueExA:Long(hKey:Int,ValueName$z,Reserved:Int,nType:Int,Bytes:Byte Ptr,size:Int)
   Function RegDeleteValueA:Long(hKey:Int,ValueName$z)
   Function RegEnumKeyA:Long(hKey:Int,idx:Int,Key:Byte Ptr,size:Int)
   Function RegEnumValueA:Long(hKey:Int,idx:Int,ValueName:Byte Ptr,NameSize:Byte Ptr,Reserved:Int,nType:Byte Ptr,ValueBytes:Byte Ptr,ValueSize:Byte Ptr)
   Function RegQueryValueExA:Long(hKey:Int,ValueName$z,Reserved:Int,nType:Byte Ptr,ValueBytes:Byte Ptr,ValueSize:Byte Ptr)
EndExtern

' registry roots
Const HKEY_CLASSES_ROOT:Int      = -2147483648
Const HKEY_CURRENT_USER:Int      = -2147483647
Const HKEY_LOCAL_MACHINE:Int   = -2147483646
Const HKEY_USERS:Int         = -2147483645

' Return value constants
Const REG_ERROR_SUCCESS:Int    = 0
Const REG_ERROR_EOF:Int         = 259     ' no more entries in key

' data types For keys
Const REG_SZ:Int            = 1      ' Data String
Const REG_BINARY:Int         = 3      ' Binary Data in any form.
Const REG_DWORD:Int            = 4    ' A 32-bit number.

' Global Var holding last error #
Global reg_lasterr:Int      = REG_ERROR_SUCCESS

?win32

' enumerates the keys contained in the passed subkey And returns them as a delimited String in
' the format: KEY=VALUE|KEY=VALUE|KEY=VALUE
Function reg_enumvalues:String(RegKey:Int,SubKey:String,delim:String="|",types=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=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 RegEnumValueA(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

' enumerates the keys contained in the passed subkey And returns them as a delimited String in
' the format: KEY|KEY|KEY
Function reg_enumkeys:String(RegKey:Int,SubKey:String,delim:String="|")
   Local cRetVal:String=""
   Local keybank=CreateBank(100)
   Local nIdx=0

   ' open the key first   
   Local hKey=reg_openkey(RegKey,SubKey:String)
   If hKey<>-1   
      Repeat         
         If RegEnumKeyA(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

' deletes a value from the registry.  returns True/False.
Function reg_deletevalue:Int(RegKey:Int,SubKey:String,ValueName:String)
   Local hKey=reg_openkey(RegKey,SubKey:String)
   Local lRetVal=False
   If hKey<>-1
      Local nRslt=RegDeleteValueA(hKey,ValueName:String)      
      If (nRslt=REG_ERROR_SUCCESS)
         lRetVal=True
      Else
         reg_lasterr=nRslt
      EndIf
      reg_closekey(hKey)
   EndIf
   Return lRetVal
End Function

' gets a value from the registry And returns it as a string.  will Return the passed Default
' If the value requested is Not found in the registry.
Function reg_getvalue:String(RegKey:Int,SubKey:String,ValueName:String,Dflt:String="",types=False)
   Local cRetVal:String=Dflt:String
   Local hKey=reg_openkey(RegKey,SubKey:String)
   Local char=0,nType=0
   
   ' open the key
   If hKey<>-1
      Local valbank=CreateBank(100),valbanksize=CreateBank(4),typebank=CreateBank(4)
   
      ' init the banks
      PokeInt(typebank,0,0)
      PokeInt(valbanksize,0,100)
   
      Local nRslt=RegQueryValueExA(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

' sets a value in the registry.  defaults To Type String, but can pass REG_DWORD And REG_BINARY.
' returns True/False.
Function reg_setvalue:Int(RegKey:Int,SubKey:String,ValueName:String,Value:String,nType=REG_SZ)
   Local hKey=reg_openkey(RegKey:Int,SubKey:String)
   Local lRetVal=False
   If hKey<>-1
      Local valbank
      
      ' 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=RegSetValueExA(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

' deletes the passed key from the registry.  returns True/False.
Function reg_deletekey:Int(RegKey:Int,KeyName:String)
   reg_lasterr=REG_ERROR_SUCCESS
   Local nRslt=RegDeleteKeyA(RegKey,KeyName:String)
   
   If nRslt<>REG_ERROR_SUCCESS
      reg_lasterr=nRslt
   EndIf
   
   Return (nRslt=REG_ERROR_SUCCESS)
End Function

' returns the registry handle Or -1 If failed.
Function reg_createkey:Int(RegKey:Int,KeyName:String)
   reg_lasterr=REG_ERROR_SUCCESS
   Local regbank=CreateBank(4)
   Local hKey=-1

   Local nRslt=RegCreateKeyA(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

' returns the registry handle Or -1 If failed
Function reg_openkey:Int(RegKey:Int,KeyName:String)
   reg_lasterr=REG_ERROR_SUCCESS
   Local regbank=CreateBank(4)
   Local hKey=-1

   Local nRslt=RegOpenKeyA(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

' closes the registry key.  returns True/False.
Function reg_closekey:Int(RegKey:Int)
   reg_lasterr=REG_ERROR_SUCCESS
   Local nRslt:Int=RegCloseKeyA(RegKey)
   
   If nRslt<>REG_ERROR_SUCCESS
      reg_lasterr=nRslt
   EndIf
   
   Return (nRslt=REG_ERROR_SUCCESS)
End Function

' returns True If the key exists
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

?


Neuer Error Laughing :
Zitat:
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0x1b3): undefined reference to `RegEnumValueA@32'
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0x428): undefined reference to `RegEnumKeyA@16'
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0x562): undefined reference to `RegDeleteValueA@8'
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0x6cb): undefined reference to `RegQueryValueExA@24'
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0x999): undefined reference to `RegSetValueExA@24'
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0x9fd): undefined reference to `RegDeleteKeyA@8'
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0xa90): undefined reference to `RegCreateKeyA@12'
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0xb45): undefined reference to `RegOpenKeyA@12'
C:/Programme/BlitzMax/mod/btbn.mod/regedit.mod.stop/.bmx/regedit.bmx.gui.release.win32.o(code+0xbab): undefined reference to `RegCloseKeyA@4'
  • Zuletzt bearbeitet von BtbN am Mi, Dez 28, 2005 16:08, insgesamt einmal bearbeitet

maximilian

BeitragMi, Dez 28, 2005 16:03
Antworten mit Zitat
Benutzer-Profile anzeigen
Weil der Extern-Code nichts macht. Erst bei den Funktionsaufrufen wird gemeckert. Fehlerquelle 1 sind hier wohl immer die Pointer. Schau ob du auch Varptr etc. richtig benutzt hast, falls vorhanden.
Variety is the spice of life. One day ignore people, next day annoy them.

BtbN

BeitragMi, Dez 28, 2005 16:09
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich benutze nur BankBuf, und schreibe dann das ganze Var-Zeugs in die Banks, wies auch beim alten BB war.

Suco-X

Betreff: ........

BeitragMi, Dez 28, 2005 18:26
Antworten mit Zitat
Benutzer-Profile anzeigen
So klappt es.

Code: [AUSKLAPPEN]

Import "-ladvapi32"

Extern "win32"
   Function RegFlushKey:Long(hKey:Int)="RegFlushKeyA@4"
   Function RegOpenKey:Long(hKeyParent:Int,SubKey$z,phkResult:Byte Ptr)="RegOpenKeyA@12"
   Function RegCloseKey:Long(hKey:Int)="RegCloseKey@4"
   Function RegCreateKey:Long(hKeyParent:Int,SubKey$z,phkResult:Byte Ptr)="RegCreateKeyA@12"
   Function RegDeleteKey:Long(hKeyParent:Int,SubKey$z)="RegDeleteKeyA@8"
   Function RegSetValue:Long(hKey:Int,ValueName$z,Reserved:Int,nType:Int,Bytes:Byte Ptr,size:Int)="RegSetValueExA@24"
   Function RegDeleteValue:Long(hKey:Int,ValueName$z)="RegDeleteValueA@8"
   Function RegEnumKey:Long(hKey:Int,idx:Int,Key:Byte Ptr,size:Int)="RegEnumKeyA@16"
   Function RegEnumValue:Long(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:Long(hKey:Int,ValueName$z,Reserved:Int,nType:Byte Ptr,ValueBytes:Byte Ptr,ValueSize:Byte Ptr)="RegQueryValueExA@24"
EndExtern

' registry roots
Const HKEY_CLASSES_ROOT:Int      = -2147483648
Const HKEY_CURRENT_USER:Int      = -2147483647
Const HKEY_LOCAL_MACHINE:Int   = -2147483646
Const HKEY_USERS:Int         = -2147483645

' Return value constants
Const REG_ERROR_SUCCESS:Int    = 0
Const REG_ERROR_EOF:Int         = 259     ' no more entries in key

' data types For keys
Const REG_SZ:Int            = 1      ' Data String
Const REG_BINARY:Int         = 3      ' Binary Data in any form.
Const REG_DWORD:Int            = 4    ' A 32-bit number.

' Global Var holding last error #
Global reg_lasterr:Int      = REG_ERROR_SUCCESS

?win32

' enumerates the keys contained in the passed subkey And returns them as a delimited String in
' the format: KEY=VALUE|KEY=VALUE|KEY=VALUE
Function reg_enumvalues:String(RegKey:Int,SubKey:String,delim:String="|",types=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=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

' enumerates the keys contained in the passed subkey And returns them as a delimited String in
' the format: KEY|KEY|KEY
Function reg_enumkeys:String(RegKey:Int,SubKey:String,delim:String="|")
   Local cRetVal:String=""
   Local keybank=CreateBank(100)
   Local nIdx=0

   ' open the key first   
   Local hKey=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

' deletes a value from the registry.  returns True/False.
Function reg_deletevalue:Int(RegKey:Int,SubKey:String,ValueName:String)
   Local hKey=reg_openkey(RegKey,SubKey:String)
   Local lRetVal=False
   If hKey<>-1
      Local nRslt=RegDeleteValue(hKey,ValueName:String)     
      If (nRslt=REG_ERROR_SUCCESS)
         lRetVal=True
      Else
         reg_lasterr=nRslt
      EndIf
      reg_closekey(hKey)
   EndIf
   Return lRetVal
End Function

' gets a value from the registry And returns it as a string.  will Return the passed Default
' If the value requested is Not found in the registry.
Function reg_getvalue:String(RegKey:Int,SubKey:String,ValueName:String,Dflt:String="",types=False)
   Local cRetVal:String=Dflt:String
   Local hKey=reg_openkey(RegKey,SubKey:String)
   Local char=0,nType=0
   
   ' open the key
   If hKey<>-1
      Local valbank=CreateBank(100),valbanksize=CreateBank(4),typebank=CreateBank(4)
   
      ' init the banks
      PokeInt(typebank,0,0)
      PokeInt(valbanksize,0,100)
   
      Local nRslt=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

' sets a value in the registry.  defaults To Type String, but can pass REG_DWORD And REG_BINARY.
' returns True/False.
Function reg_setvalue:Int(RegKey:Int,SubKey:String,ValueName:String,Value:String,nType=REG_SZ)
   Local hKey=reg_openkey(RegKey:Int,SubKey:String)
   Local lRetVal=False
   If hKey<>-1
      Local valbank
     
      ' 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=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

' deletes the passed key from the registry.  returns True/False.
Function reg_deletekey:Int(RegKey:Int,KeyName:String)
   reg_lasterr=REG_ERROR_SUCCESS
   Local nRslt=RegDeleteKey(RegKey,KeyName:String)
   
   If nRslt<>REG_ERROR_SUCCESS
      reg_lasterr=nRslt
   EndIf
   
   Return (nRslt=REG_ERROR_SUCCESS)
End Function

' returns the registry handle Or -1 If failed.
Function reg_createkey:Int(RegKey:Int,KeyName:String)
   reg_lasterr=REG_ERROR_SUCCESS
   Local regbank=CreateBank(4)
   Local hKey=-1

   Local nRslt=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

' returns the registry handle Or -1 If failed
Function reg_openkey:Int(RegKey:Int,KeyName:String)
   reg_lasterr=REG_ERROR_SUCCESS
   Local regbank=CreateBank(4)
   Local hKey=-1

   Local nRslt=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

' closes the registry key.  returns True/False.
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

' returns True If the key exists
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

?


Er will komischerweise, dass man die Lib importiert und die @BytesVonDenFlags. Die Returntypen würde ich bei fehlern übrigens auf int umstellen, Bmax hats da komischerweise nicht so mit der Long Rückgabe von externen Libs. Hatte da früher schonmal Probleme mit.
Den Umweg über die Banken kannst du dir übrigens auch sparen.
Mfg Suco
Intel Core 2 Quad Q8300, 4× 2500 MHz, 4096 MB DDR2-Ram, GeForce 9600GT 512 MB

BtbN

BeitragMi, Dez 28, 2005 18:40
Antworten mit Zitat
Benutzer-Profile anzeigen
Hast du NUR dieses import da oben hingeschreiben, oder hast du noch etwas geändert?
Und was meinst du mit Umweg über die Banken?
Was kann ich denn sonst nehmen?

Suco-X

Betreff: .......

BeitragMi, Dez 28, 2005 19:08
Antworten mit Zitat
Benutzer-Profile anzeigen
Naja, das Import und das "FunctionsName@ByteanzahlDerParameter"
Mit dem Umweg über Bank meine ich:

Code: [AUSKLAPPEN]

Function reg_createkey:Int(RegKey:Int,KeyName:String)
   reg_lasterr=REG_ERROR_SUCCESS
   Local regbank=CreateBank(4)
   Local hKey=-1

   Local nRslt=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



Ist nichts weiter als

Code: [AUSKLAPPEN]

   Local Temp:Int
   Local nRslt = RegCreateKey(RegKey:Int,KeyName:String,Varptr(nRslt))
   Print Temp


Denn wir sind hier nicht mehr beim alten BB.
Mfg Suco
Intel Core 2 Quad Q8300, 4× 2500 MHz, 4096 MB DDR2-Ram, GeForce 9600GT 512 MB

BtbN

BeitragMi, Dez 28, 2005 21:54
Antworten mit Zitat
Benutzer-Profile anzeigen
Aber das würde doch ein Int Ptr, aber wird nicht ein Byte Ptr erwartet?
Oda kann ich da getrost auch Int Ptr in die Funktion beim Extern schreiben?

Suco-X

Betreff: .......

BeitragMi, Dez 28, 2005 23:41
Antworten mit Zitat
Benutzer-Profile anzeigen
Ja ne, an nem Byte ptr kannst du jede Art von Pointer übergeben (Int, Float, Short usw.).
Die Funktion (In dem Fall die DLL Funktion) castet sich den Byte Pointer dann wieder richtig zurecht.
Mfg Suco
Intel Core 2 Quad Q8300, 4× 2500 MHz, 4096 MB DDR2-Ram, GeForce 9600GT 512 MB

BtbN

BeitragDo, Dez 29, 2005 10:54
Antworten mit Zitat
Benutzer-Profile anzeigen
wuste ich noch garnicht, thx, wird sofort geändert!

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group