Can anyone help me to translate this delphi code into MASM code? I am not looking for all of the answers, maybe just hints on how to properly do this before I destroy my registry or something.

function ReadRegistry(RootKey: Cardinal; KeyStr, Value: String): string; //read registry values (strings)

var
dwKeySize: DWORD;
Key: HKEY;
dwType: DWORD;
begin
if
RegOpenKeyEx(RootKey, PChar(KeyStr), 0, KEY_READ, Key) = ERROR_SUCCESS
then
try
RegQueryValueEx(Key, PChar(Value), nil, @dwType, nil, @dwKeySize);
if (dwType in [REG_SZ, REG_EXPAND_SZ]) and (dwKeySize > 0) then
begin
SetLength(Result, dwKeySize);
RegQueryValueEx(Key, PChar(Value), nil, @dwType, PByte(PChar(Result)),
@dwKeySize );
end
else
begin
RegQueryValueEx(Key, PChar(Value), nil, @dwType, nil, @dwKeySize);
if (dwType in [REG_SZ, REG_EXPAND_SZ]) and (dwKeySize > 0) then
begin
SetLength(Result, dwKeySize);
RegQueryValueEx(Key, PChar(Value), nil, @dwType, PByte(PChar(Result)),
@dwKeySize);
end;
end;
finally
RegCloseKey(Key);
end;
end;


The procedure does not need to work the way the one above does. It can all be local without needing to pass parameters to it. Just keeping everything localized.

I guess my problem here is the IF statements that I used in the code above; How do I translate them into MASM code?

If you can help, thank you very much! :grin:
Posted on 2003-05-29 20:39:29 by The Beginner
I believe you are asking how to translate Delphi's conditional statements into something Masm understands? The Masm32 help file covers the various high level syntax that Masm 6.0 and higher can use. I hope I am not off base when I suggest the following (which only shows a little detail):



invoke RegOpenKeyEx(xxx, xxx, xxx, xxx, xxx)
mov resultRegOpen, eax

.IF (resultRegOpen == 0) ;comparison could have been done directly with eax I believe
RegQueryValueEx()

...
...

.ELSE

...
...

.ENDIF


Hopefully someone with more experience can clarify if this does not help.
Posted on 2003-05-30 00:20:30 by Masmer
Don't bother to mov to memory then compare with memory. Just compare with reg like


invoke RegOpenKeyEx,xxx, xxx, xxx, xxx, xxx
test eax,eax
jnz @F
..
@@:
...

Something like that.
Posted on 2003-05-30 05:58:34 by roticv
Thanks for the help, guys. Here is what I got, in case anyone can improve on it or use it.



invoke RegOpenKeyEx, HKEY_LOCAL_MACHINE, addr RSectn, NULL, KEY_READ, NULL
mov regResult, eax

.if (regResult != ERROR_SUCCESS)
mov KeyExists, 1 [color=green];Give value of 1 if the procedure succeeds[/color]
.else
mov KeyExists, 0 [color=green];Otherwise, give the value of 0[/color]
.endif
invoke RegCloseKey, HKEY_LOCAL_MACHINE
ret
Posted on 2003-05-31 12:22:09 by The Beginner