Thread: ERRPR: Object reference not set to an instance of an object

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    3

    ERRPR: Object reference not set to an instance of an object

    Hey when ever i start debugging my program i get this one error that causes the program to crash. the error is :Object reference not set to an instance of an object

    Here is the part of the code that needs to be seen:
    Code:
    Microsoft::Win32::RegistryKey^ key = Microsoft::Win32::Registry::CurrentUser->OpenSubKey( "Software\\Policies\\Microsoft\\Windows\\System\\DisableCMD");
    		System::Object^ result;
    		result = key->GetValue("DisableCMD");
    		String^ val = result->ToString();
    		System::Windows::Forms::MessageBox::Show(val);
    I always get the error at the line:
    result = key->GetValue("DisableCMD");

    Error:An unhandled exception of type 'System.NullReferenceException' occurred in mscorlib.dll

    Additional information: Object reference not set to an instance of an object.

    I checked to make sure the value existed and it did, but even if the value doesn't exist, i thought it would just set the variable equal to 'null' but maybe i am wrong. if someone could help me with this problem i would be very grateful.
    Last edited by blackhack; 07-13-2005 at 07:31 PM.

  2. #2
    Registered User
    Join Date
    Jul 2005
    Posts
    22
    Is there a registry key at the address you're pointing to? The first thing that comes to my mind is that there isn't, so key actually gets set to null, and it crashed when you call GetValue on a null pointer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. how to get the reference of the object in C++
    By maxcat in forum Windows Programming
    Replies: 6
    Last Post: 03-06-2008, 07:27 PM
  3. Replies: 4
    Last Post: 01-23-2008, 06:21 AM
  4. "Object reference not set to an instance of an object"
    By Manitoadlet in forum C++ Programming
    Replies: 6
    Last Post: 09-10-2002, 06:09 PM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM