Thread: 0xC0000005: Access Violation

  1. #1
    Registered User Strider's Avatar
    Join Date
    Aug 2001
    Posts
    149

    0xC0000005: Access Violation

    I keep running in Access Violations while running through the DirectX 8 Init functions. Here is an example where I receive an 0xC0000005: Access Violation. Any one have an idea of what may be the cause?
    Code:
    // directinput globals
    LPDIRECTINPUT8       lpdi      = NULL;    // dinput object
    LPDIRECTINPUTDEVICE8 lpdikey   = NULL;    // dinput keyboard
    
    int DInput_Init_Keyboard(void)
    {
    	// this function initializes the keyboard device
    
    	// create the keyboard device  
            // get 0xC0000005: Access Violation here 
    	if (lpdi->CreateDevice(GUID_SysKeyboard, 
    			&lpdikey, 
    			NULL) != DI_OK)
    	{
    		return(0);
    	}
    
    	// set cooperation level
    	if (lpdikey->SetCooperativeLevel(main_window_handle, 
    				DISCL_NONEXCLUSIVE | 
    				DISCL_BACKGROUND) != DI_OK)
    	{
    		return(0);
    	}
    
    	// set data format
    	if (lpdikey->SetDataFormat(&c_dfDIKeyboard)!=DI_OK)
    		return(0);
    
    	// acquire the keyboard
    	if (lpdikey->Acquire()!=DI_OK)
    		return(0);
    
    	// return success
    	return(1);
    } // end DInput_Init_Keyboard
    Thanks,
    David
    One Ring to rule them all, One Ring to find them,
    One Ring to bring them all and in the darkness bind them
    In the Land of Mordor where the Shadows lie.

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Does lpdi point to a valid DirectInput object?
    zen

  3. #3
    Registered User Strider's Avatar
    Join Date
    Aug 2001
    Posts
    149
    I initialize it with this function:
    Code:
    int DInput_Init(void)
    {
    	// this function initializes directinput
    
    	if(FAILED(DirectInput8Create(g_hinst,
    				DIRECTINPUT_VERSION,
    				IID_IDirectInput8,
    				(void **)&lpdi,
    				NULL)))
    	{
    		return(0);
    	}
    
    	// return success
    	return(1);
    } // end DInput_Init
    It seems to fail and return 0 here. When lpdi is referenced again it has a NULL value (0xC0000000). How can I correct this?

    David
    One Ring to rule them all, One Ring to find them,
    One Ring to bring them all and in the darkness bind them
    In the Land of Mordor where the Shadows lie.

  4. #4
    Registered User Strider's Avatar
    Join Date
    Aug 2001
    Posts
    149
    I believe I found my error. I was saving the HINSTANCE by declaring:
    extern HINSTANCE main_instance;

    But I was using:
    HINSTANCE hinstance_app;

    to save the instance in my driver program.

    Thanks for the help,
    David
    One Ring to rule them all, One Ring to find them,
    One Ring to bring them all and in the darkness bind them
    In the Land of Mordor where the Shadows lie.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Access violation... can't figure it out...
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 10-11-2007, 10:52 AM
  2. access violation in int array
    By George2 in forum C Programming
    Replies: 2
    Last Post: 08-02-2007, 11:28 PM
  3. Copying memory, pointers and the like.
    By psychopath in forum C++ Programming
    Replies: 34
    Last Post: 12-12-2006, 01:37 PM
  4. FtpFileFind access violation with MS VC++ 6.0
    By earth_angel in forum C++ Programming
    Replies: 3
    Last Post: 09-22-2005, 07:02 PM
  5. Replies: 5
    Last Post: 07-13-2003, 01:01 PM