Crash!

Started by
14 comments, last by Zeblar Nagrim 20 years, 11 months ago
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.
Advertisement
not to be unhelpful or anything, but if you wrote it, shouldn''t you know why? Or are you just copying other peoples code?
I have written this code. It works on my computer (win2000)
but not on a friends computer (winXP).
What is it supposed to do?

-~-The Cow of Darkness-~-
-~-The Cow of Darkness-~-
Nothing, just a test! Try to open a key "named "SOFTWARE\\HATEREG\\" in HKEY_LOCAL_MACHINE, then close that key and create it again.
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.
I should probably be working now...
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.
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.
I should probably be working now...
No it does not, not for me , but can things like this cause the OS to crash? That is the question.
Yes.

-~-The Cow of Darkness-~-
-~-The Cow of Darkness-~-

This topic is closed to new replies.

Advertisement