0xC0000005: Access Violation

This is a discussion on 0xC0000005: Access Violation within the Windows Programming forums, part of the Platform Specific Boards category; I keep running in Access Violations while running through the DirectX 8 Init functions. Here is an example where I ...

  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
    zen
    zen is offline
    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, 11:52 AM
  2. access violation in int array
    By George2 in forum C Programming
    Replies: 2
    Last Post: 08-03-2007, 12:28 AM
  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, 08:02 PM
  5. Replies: 5
    Last Post: 07-13-2003, 02:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21