Skip to main content
gamedev.net
🔒 Locked

Crash!

Started by Zeblar Nagrim 14 replies 650+ views
Original Post
Zeblar Nagrim
Zeblar Nagrim
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.
cowsarenotevil
cowsarenotevil
What is it supposed to do?

-~-The Cow of Darkness-~-
-~-The Cow of Darkness-~-
stu_pb
stu_pb
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...
Zeblar Nagrim
Zeblar Nagrim
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.
stu_pb
stu_pb
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...
cowsarenotevil
cowsarenotevil
Yes.

-~-The Cow of Darkness-~-
-~-The Cow of Darkness-~-
cowsarenotevil
cowsarenotevil
quote:
Original post by Zeblar Nagrim
Yes?


Yes, it can cause the os to crash. The registry is part of the os. Messing it up is bad.

-~-The Cow of Darkness-~-
-~-The Cow of Darkness-~-
thy MC
thy MC
HEY
LET ME CLARIFY SOME THINGS FOR YOU

Writing into the registry is NO MONKEY BUSINESS
Please AGREE or I will LIBERATE you

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.