Archived

This topic is now archived and is closed to further replies.

Recommended Posts

This code crash the computer on windows XP:
  

#include <windows.h>

int main()
{
	HKEY hKey;
	if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\HATEREG\\", 0,
					KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
	RegCloseKey(hKey);

	DWORD ub;
	RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\HATEREG\\",
		0,TEXT(""),REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 
		NULL,&hKey,&ub); 

	return 0;
}

  
Why? Thanks.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
not to be unhelpful or anything, but if you wrote it, shouldn''t you know why? Or are you just copying other peoples code?

Share this post


Link to post
Share on other sites
what line does it crash on.

Why do you need to call RegCloseKey if the key failed to be opened, I would assume that no memory was allocated for the hkey variable so closing it should be unnecessary. I could be wrong though, I don''t know anything about these registry functions.

Share this post


Link to post
Share on other sites
Like I said. It''s only a example ripped from another project! What I don''t get is why this CRASH the os. Can this happen?

My friend have only executed the exe file, he have not access to the code so he can not track the error to a line.

Thanks.

Share this post


Link to post
Share on other sites
try creating the key manually first and then run the program again. If is doesn''t crash then the call to RegCloseKey is causing the crash since the variable hKey is NULL.

Share this post


Link to post
Share on other sites
quote:
Original post by thy MC
HEY
LET ME CLARIFY SOME THINGS FOR YOU

Writing into the registry is NO MONKEY BUSINESS


Thats ok, I didn''t want your help anyway.

Share this post


Link to post
Share on other sites