Jump to content
Sign in to follow this  
Guest bartels

DirectInput initialization in gauges

Recommended Posts

From the DX9 SDK, DInput Tut 1: Using the keyboard:

[font color="blue"]//[/font] [font color="green"]HINSTANCE  g_hinst;[/font] [font color="blue"]//[/font] [font color="green"]initialized earlier[/font][font color="black"]HRESULT		 hr; LPDIRECTINPUT8  g_lpDI; hr = DirectInput8Create(g_hinst, DIRECTINPUT_VERSION, 		IID_IDirectInput8, (void**)&g_lpDI, NULL); if FAILED(hr) { [/font]	[font color="blue"]//[/font] [font color="green"]DirectInput not available; take appropriate action [/font][font color="black"]}[/font]

How to adapt that very first initialization code for use in gauges? Why should I have initialized g_hinst earlier? I am always getting errors with DirectInput8Create.Etienne :-wave

Share this post


Link to post
Share on other sites
Guest bartels

This is from a DInput access to joystick made by me, more or less an unchanged example codeStoreInstanceHandle is just an "outsorced"

g_hinst=(HINSTANCE)extra_data

ReadJoystick is

DIJOYSTATE joystick		=	UpdateInputState(fswnd);

with extra stuff.

void FSAPI gauge_cb( PGAUGEHDR pgauge, int service_id, UINT32 extra_data ){	static	HWND	fswnd=NULL;	switch(service_id)	{		case	PANEL_SERVICE_PRE_INSTALL		:			fswnd	=	FindWindow("FS98MAIN",NULL);			StoreInstanceHandle((HINSTANCE)extra_data);			InitDirectInput(fswnd);			SetAcquire(fswnd);						break;...		case	PANEL_SERVICE_PRE_UPDATE:			ReadJoystick(fswnd);						..			break;...		case	PANEL_SERVICE_PRE_KILL		:			FreeDirectInput();						break;	}}

The keybord acces can't be much different.Arne Bartels

Share this post


Link to post
Share on other sites

Oh. So actually no CreateBlaBlaBla req'd at all?But "FS98MAIN"?? Is that up to date? :-)

Share this post


Link to post
Share on other sites
Guest bartels

InitDirectTinput is copied from the joystick sample and it contains a DirectInputCreate.FS98MAIN does work and would work from FS98 CFS FS2000 CFS2 to FS2002.Arne Bartels

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

>StoreInstanceHandle is just an "outsorced">

g_hinst=(HINSTANCE)extra_data

Do not see anything like this in the current sample code. Also, not sure what the "extra data" is.... is this the handle of the gauge's window, vs. the FS window?>ReadJoystick is

DIJOYSTATE>joystick		=	UpdateInputState(fswnd);

This I understand. =)>

>void FSAPI gauge_cb( PGAUGEHDR pgauge, int service_id, UINT32>extra_data )>{>	static	HWND	fswnd=NULL;>	switch(service_id)>	{>		case	PANEL_SERVICE_PRE_INSTALL		:>			fswnd	=	FindWindow("FS98MAIN",NULL);>			StoreInstanceHandle((HINSTANCE)extra_data);>			InitDirectInput(fswnd);>			SetAcquire(fswnd);>                        break;>...>		case	PANEL_SERVICE_PRE_UPDATE:>			ReadJoystick(fswnd);>                        ..>			break;>...>		case	PANEL_SERVICE_PRE_KILL		:>			FreeDirectInput();>                        break;>	}>}Just wondering if this init and cleanup code can go in one gauge of a multi-gauge, or even in module_init / deinit.

Share this post


Link to post
Share on other sites

Just wondering if this init and cleanup code can go in one gauge of a multi-gauge, or even in module_init / deinit.I like the module_init route; can't see why it wouldn't work. Problem with the PRE-INITIALIZE/PRE-KILL routine is that every time the user toggles a panel window or hits , DirectInput will be killed and restarted.Doug

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Yes, exactly, which is why I do DirectSound stuff there... I have a feeling that Arne wrote this before FSX, and so it worked then.What a pain to have to take the two samples they give and integrate it to be able to do both keyboard and joystick.I just got done learning DirectSound so I could implement XACT, and I really don't feel like having to learn DirectInput too :(It seems I have no choice as I have to be able to push this button from the joystick, and have it stay down while the joystick button is pressed.If someone wants to trade working DirectInput keyboard and joystick stuff for working XACT stuff, I"m all ears :)XACT is very cool, as you can easily compose sounds into tracks and tracks into cues that are triggered by the game easily. You can loop, and trail sounds, and adjust volume and envelopes dynamically etc. Very cool stuff if you haven't looked at it.

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Lucky DirectInput is soo much easier than DirectSound.Got it all working now :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...