473,386 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

DirectInput help

52
I'm trying to use DirectInput in the DirectX SDK to do USB
reading (a device as joystick). There's no error when compiling the codes but whenever it
tries to excecute:

g_pDI->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback,
NULL, DIEDFL_ATTACHEDONLY);

where

BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE*
pdidInstance, VOID* pContext)
{
HRESULT hr;

// Obtain an interface to the enumerated joystick.
hr = g_pDI->CreateDevice(pdidInstance->guidInstance,
&joystick, NULL);
if(FAILED(hr))
return DIENUM_CONTINUE;

return DIENUM_STOP;
}

...I get "A first chance exception of
type 'System.NullReferenceException' occurred in test.exe" error
message; the program could still continue but it would just throw
the exception and doesn't do what it is supposed to do.

I've tested it by placing a flag in EnumJoysticksCallback and it
seems to me that it is not the callback function that is causing
the problem.

Appreciate any suggestion :]
Oct 4 '08 #1
5 2286
weaknessforcats
9,208 Expert Mod 8TB
Have you Googled NullReferenceException?
Oct 4 '08 #2
200dogz
52
Have you Googled NullReferenceException?
Yea, one of the answer I found was to disable it completely when compiling the program. However, when I ran the program it stills threw an exception in that line so I'd imagine I need to try and fix it somehow.
Oct 4 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
g_pDI, pdidInstance, and guidInstance are all non-zero?
Oct 4 '08 #4
200dogz
52
g_pDI, pdidInstance, and guidInstance are all non-zero?
I don't think I initialised those...so that might be the problem.

Anyway I was told that the way I was doing (following a directInput tutorial) would not work for Form Application that I'm using.

It seems that I need to use something like
virtual void Form1::WndProc(Message% m) override {
if(m.Msg == WM_DEVICECHANGE) {
//do stuff
instead....

Thanks for your help tho =]]
Oct 5 '08 #5
200dogz
52
Perhaps instead of trying to fix the codes I have here that might be completely wrong, I should just ask method of reaching the goal...

I have a Form application with one button and a textbox. How should I approach if I want the program to display the X value of a joystick plugged in the USB port of the PC when the button is pressed? I heard from a friend it should only take around 20 lines to do so.

Thanks for helping :)
Oct 5 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
0
by: DD | last post by:
I have been searching for an example of steering wheel input using DirectInput managed code. Is there a code snippet available to show how this is done? Thanks
1
by: shrinerain | last post by:
Hello everyone,I want to use a joystick to control my computer, I know DirectInput can do this job,but I can't find any example.Do you have an example that use DirectInput in C#? Please help...
0
by: sri_san | last post by:
I am new to directx API and looking to make it work with C#. I was able to get the state of joystick by polling it at regular intervals. I am trying to make it work based on events. Here is a link...
5
by: Steve | last post by:
does anyone know where i can find an example of directinput for a joystick on VB.NET. all the examples i can find apply to vb 6.0. Thanks Steve
2
by: Vicente Nicolau | last post by:
Hello, I'm implementig a C# app in which I need to access to a Joystick. Nowadays I'm using the DirectInput class for getting the actual joystick position, but trhough polling. I would like...
2
by: James Hallam | last post by:
Hi, I'm having trouble getting a conditional force (namely friction) using VB6. I have had no problem using constant or periodic forces. The trouble seems to be that when defining the later...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.