• Advertisement

Archived

This topic is now archived and is closed to further replies.

Dinput create crashes program?

This topic is 5358 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm making a program that uses OpenGL for graphics, and directx for input. I'm kind of a noob, so I think my problem might be caused by something very simple. Whenever I try to use DirectInput8Create() in my program I get errors [edit: the program compiles correctly, it just has problems when I run it]. I'm using Windows XP, so I get that little box that says my program has encountered an problem and needs to close (in my experience, this comes with an access violation of some sort). I have pinpointed the exact line and it is this:
  if (FAILED(DirectInput8Create(appInstance,
                               DIRECTINPUT_VERSION,
                               IID_IDirectInput8,
                               (void **)&m_pDI,
                               NULL)))
  return false; 
  
Now, I learned some simple direct input from the book "OpenGL Game Programming." If you're not familiar with it, it also includes some Direct Input stuff as well as OpenGL. I tried using the sample program from the book, and got the same error. This tells me the error probably does not have to do with my code, rather it has something to do with my system , my project settings, or my compiler. I do have dinput8 and dxguid linked to my project. I am using DevC++ for a compiler. Does anyone know what could be causing this error? [edited by - EvilProgrammer on August 17, 2003 5:12:24 PM]

Share this post


Link to post
Share on other sites
Advertisement
I''m not sure how the DevC++ compiler works but you might want to turn up the DirectInput debug spew in the control panel. The debug output might help you narrow down what could be causing the problem.

As far as your code is concerned, I do exactly the same thing and it works for me. Except that for the first parameter, I use GetModuleHandle(NULL) instead of my app instance. It should work either way but you might want to give that a try. So my function call looks like this:

// Create a IDirectInput8*
if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&m_pDI, NULL ) ) )
return DXTRACE_ERR_MSGBOX( "DirectInput8Create", hr );

Hope this helps,
neneboricua

Share this post


Link to post
Share on other sites
Well, thanks for replying. I try debugging it and it says that line raises an Access Violation (Segmentation Fault) and I think I know what that means but I don''t know how that line could possibly raise that error. It''s becoming rather depressing.

Share this post


Link to post
Share on other sites
An "Access Violation" basically means that the system tried to follow a messed up pointer somewhere. Since that function is supposed to fill in a pointer for you, I don''t see how it is causing a segmentation dump. Your problem could be that you''re not linking to the right files.

Try to run one of the sample DirectInput apps and see if it works. I''m not sure if DevC++ does this or not, but see if it will let you open up a Visual Studio project. If it does, then try to open one of the SDK''s DirectInput samples and compile it yourself. If you can run that, then try to see what the differences are between your app and the SDK''s when it comes to DirectInput. Pay special attention to the #include and #define stuff. Also take a look at the project settings and see what .lib files they include.

In case you can''t open a Visual Studio project, here are all the .lib files that I have in my current project. This was generated using the DX9 App Wizard for Visual Studio .NET

dsound.lib dinput8.lib dxerr9.lib d3dx9.lib d3d9.lib d3dxof.lib dxguid.lib winmm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comctl32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib

neneboricua

Share this post


Link to post
Share on other sites
I opened the imported the direct input keyboard example and it had these parameters:

-ldxguid -ldxerr8 -ldinput8 -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -luuid

I tried to compile the example but I got a linker error: "undefined reference to IID_IDirectInput8A". I''m not sure what''s missing.

I tried neneboricua''s libs and it compiled but I got the same error as before.

m_pDI is defined:

LPDIRECTINPUT8 m_pDI;

This is part of my InputSystem class. It''s not declared as a pointer because I send it to the DirectInput8Create() function by reference. This is how my book does it, so I''m pretty sure it''s ok, and it seems to make things simpler when I use it later on. I tried making it a pointer, just to see what would happen, but nothing was different.

Share this post


Link to post
Share on other sites
Are you using the DX9 SDK? Because if you are, you have to add a line to your #include stuff before including the Direct Input header file. The reason for this is that since DirectInput didn''t change from DX8 to DX9, you have to specifically tell the system that eventhough you have DX9 installed, you still want to use the DX8 interface for DirectInput. To do this:

#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>

Basically, you have to have that #define before you include the direct input header file.

On the other hand, if you''re using the DX8 SDK then this should be unnecessary.

Share this post


Link to post
Share on other sites

  • Advertisement