invoke RegOpenKeyEx, HKEY_LOCAL_MACHINE, addr szRegValue, 0, KEY_ALL_ACCESS, addr RegKey
invoke RegSetValueEx, RegKey, addr szRegK, 0, REG_SZ, addr szT, sizeof szT
invoke RegCloseKey, RegKey


szT is something like "c:\program files\blah...", but the code above only writes "c:\p".

regKey is a dword, szT is a dword and szRegK is a byte.

Anyone know what's wrong?

Thanks.
Posted on 2003-07-08 00:51:23 by Ghirai
Originally posted by Ghirai
invoke RegOpenKeyEx, HKEY_LOCAL_MACHINE, addr szRegValue, 0, KEY_ALL_ACCESS, addr RegKey
invoke RegSetValueEx, RegKey, addr szRegK, 0, REG_SZ, addr szT, sizeof szT
invoke RegCloseKey, RegKey


szT is something like "c:\program files\blah...", but the code above only writes "c:\p".

regKey is a dword, szT is a dword and szRegK is a byte.

Anyone know what's wrong?

Thanks.


sizeof a dword is 4 bytes, so its writing the first 4 bytes of your string? szT should be byte i think
Posted on 2003-07-08 01:11:15 by jcsn
Now it adds some "|" char or something like that at the end... :(
Posted on 2003-07-08 04:12:24 by Ghirai
How about this?
Posted on 2003-07-08 09:24:12 by QvasiModo

Now it adds some "|" char or something like that at the end... :(


Yeah, sizeof includes the null at the end (I think), so that "|" is the null character. QvaziModo's will work. :alright:
Posted on 2003-07-08 09:43:10 by jcsn
If the length of your string is known at assembly time, you could also try sizeof szT - 1. The "-1" will keep the trailing zero out of your string.
Posted on 2003-07-08 16:04:28 by QvasiModo
I don't know the len at assembly time.
Thanks guys, i'll try :)
Posted on 2003-07-09 01:00:05 by Ghirai
nope, still not working.
only the first 3 chars get written ;(
Posted on 2003-07-10 09:56:59 by Ghirai
I don't understand why its not working? because this example using the same method
QvasiModo posted works just fine.



; #################################################

.486
.model flat, stdcall
option casemap :none ; case sensitive

; #################################################

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\advapi32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\advapi32.lib

main PROTO
.data
hRegKey dd 0
disp dd 0

SubKey db "Software\RobotBob\RegStrWriteExample",0
TestKey db "TestString",0
StringToWrite db "The quick brown fox jumps over the lazy dogs back",0

; #################################################
.code

start:
invoke RegCreateKeyEx,HKEY_CURRENT_USER,OFFSET SubKey,0,0,REG_OPTION_NON_VOLATILE, \
KEY_ALL_ACCESS, NULL,OFFSET hRegKey, OFFSET disp
invoke lstrlen,OFFSET StringToWrite
invoke RegSetValueEx,hRegKey, OFFSET TestKey, 0, REG_SZ, OFFSET StringToWrite, eax
invoke RegCloseKey,hRegKey

invoke ExitProcess,0
; #################################################

end start


maybe post your full code (i mean even the data you pass it, maybe there is something screwy with your string?!?)

RobotBob
Posted on 2003-07-10 10:41:34 by RobotBob
Here is a ScreenShot of it working....
Posted on 2003-07-10 10:46:18 by RobotBob
Yeah, i made a quick test with such a example too, and it works, but when i try the same thing in my app, it doesn't;
I don't know the StringToWrite at asm time; i don't know what type it should be; i tryed byte, dword, and lpstr, but, with small diffs, only the first chars got written.
I'm not @ home right now, but i'll post the snippet.
Posted on 2003-07-11 12:27:08 by Ghirai
Increase the size of the buffer or heap.
Posted on 2003-07-12 11:05:11 by Poimander
Oh, so how would i do that?
Posted on 2003-07-14 00:15:54 by Ghirai