First off, I'm using the registry to auto-run my application.
I use this code to add the AR entry. This is not all of the code. It's trimmed down a bit.
My main question is should I use "sizeof Self" or should I do the following:
Which is better?
Also, if I want to check if a value exists in the registry (i.e checking to see if a value exists before using SHGetValue) do I have to use the Reg* API functions or do I just use SHGetValue with error checking? If anyone would be willing, a code snippet would be very grateful.
I use this code to add the AR entry. This is not all of the code. It's trimmed down a bit.
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\shlwapi.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\shlwapi.lib
.data
szARKey db "Software\Microsoft\Windows\CurrentVersion\Run", 0
szARValue db "FireAmp", 0
Self db MAX_PATH DUP(?)
.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
.code
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke GetModuleFileName, NULL, offset Self, MAX_PATH
invoke SHSetValue, HKEY_LOCAL_MACHINE,
offset szARKey,
offset szARValue,
REG_SZ,
offset Self,
sizeof Self
invoke ExitProcess, NULL
end start
My main question is should I use "sizeof Self" or should I do the following:
invoke lstrlen, offset Self
invoke SHSetValue, HKEY_LOCAL_MACHINE,
offset szARKey,
offset szARValue,
REG_SZ,
offset Self,
eax
Which is better?
Also, if I want to check if a value exists in the registry (i.e checking to see if a value exists before using SHGetValue) do I have to use the Reg* API functions or do I just use SHGetValue with error checking? If anyone would be willing, a code snippet would be very grateful.
"sizeof self" won't work (well, it'll probably work, but is not the correct way to do it) since it's a dynamic string - you'll need lstrlen, or some other "get string length" routine.
So (sorry to sound naive) what does sizeof return exactly?
Edit (to save "space"): Thanks f0dder!
Edit (to save "space"): Thanks f0dder!
sizeof returns the (static) size of a variable, determined at assemble-time. So for Self db MAX_PATH DUP(?), it would return MAX_PATH (160, iirc) regardless of the amount of characters placed in Self.
just remember that it's good etiquette to give the user the option of whether or not to autorun your software or not. especially when modding the reg. you might already do that but it's just my 2 cents.