huiyi_ch wrote: ↑Wed May 17, 2017 4:58 am
I have an application that needs to write binary keys to the registry.
If I should be in
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedMRU] writes the following data:
"a"=hex:6e,00,6f,00,74,00,65,00,70,00,61,00,64,00,2e,00,65,00,78,00,65,00,00,\
00,44,00,3a,00,5c,00,44,00,45,00,56,00,5c,00,53,00,63,00,72,00,69,00,70,00,\
74,00,45,00,64,00,69,00,74,00,5c,00,56,00,42,00,53,00,45,00,64,00,69,00,74,\
00,5c,00,56,00,42,00,53,00,00,00
How do I implement them?
Thanks in advance.
Hi huiyi_ch.
There is a bug in win_reg.prg in Harbour sources that prevents the registry from writing values in binary data.
I modified it by adding an array support with binary data or a binary string.
It seems to me that it should solve your problem.
Code: Select all
#include "hmg.ch"
#include "hbwin.ch"
*********************************************
PROCEDURE Main()
Local nByte
//binary array
aReg := {0x6e,0x00,0x6f,0x00,0x74,0x00,0x65,0x00,0x70,0x00,0x61,0x00,0x64,0x00,0x2e,0x00,0x65,0x00,0x78,0x00,0x65,0x00,0x00,;
x00,0x44,0x00,0x3a,0x00,0x5c,0x00,0x44,0x00,0x45,0x00,0x56,0x00,0x5c,0x00,0x53,0x00,0x63,0x00,0x72,0x00,0x69,0x00,0x70,0x00,;
x74,0x00,0x45,0x00,0x64,0x00,0x69,0x00,0x74,0x00,0x5c,0x00,0x56,0x00,0x42,0x00,0x53,0x00,0x45,0x00,0x64,0x00,0x69,0x00,0x74,;
0x00,0x5c,0x00,0x56,0x00,0x42,0x00,0x53,0x00,0x00,0x00}
//binary string
cReg:=""
FOR EACH nByte IN aReg
cReg := cReg + Chr(nByte)
NEXT
//writing registry value as binary array
MsgInfo( win_regWrite2( "HKCU\_TEST\a", aReg, WIN_REG_BINARY ) , 'Binary Array')
//writing registry value as binary string
MsgInfo( win_regWrite2( "HKCU\_TEST\c", cReg, WIN_REG_BINARY ) , 'Binary String')
QUIT
RETURN
***********************************************************************
FUNCTION win_regWrite2( cRegPath, xValue, nType, nRegSam )
LOCAL nHKEY, cKey, cEntry
win_regPathSplit( cRegPath, @nHKEY, @cKey, @cEntry )
RETURN win_regSet2( nHKEY, cKey, cEntry, xValue, nType, nRegSam )
*************************************************************
FUNCTION win_regSet2( nHKEY, cKeyName, cEntryName, xValue, nValueType, nRegSam )
LOCAL cName
LOCAL lRetVal := .F.
LOCAL pKeyHandle
LOCAL nByte
hb_default( @nRegSam, 0 )
IF win_regCreateKeyEx( nHKEY, cKeyName, 0, 0, 0, hb_bitOr( KEY_SET_VALUE, nRegSam ), 0, @pKeyHandle )
/* no support for Arrays, Codeblock ... */
SWITCH ValType( xValue )
CASE "A" //added support for array of binary
IF ! HB_ISNUMERIC( nValueType ) .OR. !(nValueType == WIN_REG_BINARY)
cName := Nil
ELSE
cName := ''
FOR EACH nByte IN xValue
cName := cName + Chr(nByte)
NEXT
ENDIF
EXIT
CASE "L"
nValueType := WIN_REG_DWORD
cName := iif( xValue, 1, 0 )
EXIT
CASE "D"
nValueType := WIN_REG_SZ
cName := DToS( xValue )
EXIT
CASE "N"
IF ! HB_ISNUMERIC( nValueType ) .OR. ;
!( nValueType == WIN_REG_DWORD .OR. ;
nValueType == WIN_REG_DWORD_LITTLE_ENDIAN .OR. ;
nValueType == WIN_REG_DWORD_BIG_ENDIAN .OR. ;
nValueType == WIN_REG_QWORD .OR. ;
nValueType == WIN_REG_QWORD_LITTLE_ENDIAN )
nValueType := WIN_REG_DWORD
ENDIF
cName := xValue
EXIT
CASE "C"
CASE "M"
//added support for string of binary
IF ! HB_ISNUMERIC( nValueType ) .OR. ;
!( nValueType == WIN_REG_SZ .OR. ;
nValueType == WIN_REG_EXPAND_SZ .OR. ;
nValueType == WIN_REG_BINARY .OR. ;
nValueType == WIN_REG_MULTI_SZ )
nValueType := WIN_REG_SZ
ENDIF
cName := xValue
EXIT
ENDSWITCH
IF cName != NIL
lRetVal := win_regSetValueEx( pKeyHandle, cEntryName, 0, nValueType, cName )
ENDIF
win_regCloseKey( pKeyHandle )
ENDIF
RETURN lRetVal
****** END ******************