Discussion:
Direct Input Device -> GetDeviceState mysteriously fails
(too old to reply)
t***@gmail.com
2017-12-12 17:22:06 UTC
Permalink
1- It's a dumb bug in my .dll source.
I'd go for a 5% chance on that... although how about using your source in a small
exe to run and simply check that the code is all working? (ignore Matlab for now)
2- It's something Matlab is doing to screw up DirectInput.
20% but first check that Direct Input is working with another program that uses
direct input whilst Matlab is running? Would you like me to send you an exe that
uses direct input? (as a test)
3- simply because I am making the DirectInput call from a .dll, outside
75% probability and rising to 95% if 1 and 2 pass okay
So I'm writing a fake Matlab which just opens a window and loads my .dll and calls its
MexFunction() to read the keyboard.
Yes, good idea!
Thanks for the additional comments. I've had to set this aside for just a few days. I'll
be back at it the end of the week.
best,
Allen
Nearly 16 years too late, but somebody might still end up here, so I'll answer it: Calling DirectX functions within a DLL is fine, but initialising DirectX withing a DLL is not. The objects must be created within an EXE, but the devices can be created and worked with within a DLL. To clarify, DirectInput8Create() must be called within the EXE file, but DInput8->CreateDevice/SetDataFormat/Acquire() and DInputDevice8->GetDeviceState() can be called within the DLL.
JJ
2017-12-13 00:06:00 UTC
Permalink
On Tue, 12 Dec 2017 09:22:06 -0800 (PST),
Post by t***@gmail.com
Nearly 16 years too late, but somebody might still end up here, so I'll
answer it: Calling DirectX functions within a DLL is fine, but
initialising DirectX withing a DLL is not. The objects must be created
within an EXE, but the devices can be created and worked with within a
DLL. To clarify, DirectInput8Create() must be called within the EXE file,
but DInput8->CreateDevice/SetDataFormat/Acquire() and
DInputDevice8->GetDeviceState() can be called within the DLL.
Are you sure about that? Cause there's a game console emulator which uses
plugins to render the console screen. They're all DLL files, and a plugin
can either be a display renderer using Direct3D, OpenGL, GDI, or no output
at all. The host application doesn't and can't know whether the plugin uses
which graphics rendering engine. So, for the plugin which uses Direct3D, it
initializes it from the plugin DLL, not from the host EXE.
Kaz Kylheku
2017-12-13 01:32:07 UTC
Permalink
Post by t***@gmail.com
Nearly 16 years too late, but somebody might still end up here, so
And 16 miles wide of the mark.
Post by t***@gmail.com
DLL. To clarify, DirectInput8Create() must be called within the EXE
file, but DInput8->CreateDevice/SetDataFormat/Acquire() and
DInputDevice8->GetDeviceState() can be called within the DLL.
There is no such restriction; you're misreading the MSDN doc.

This API function takes a module handle. There is a requirement that
whoever is calling it must supply their module handle.

Direct (no pun intended) quote:

hInst Instance handle to the application or dynamic-link library (DLL)
that is creating the DirectInput object. DirectInput uses this
value to determine whether the application or DLL has been
certified and to establish any special behaviors that might be
necessary for backward compatibility.

See? Application or dynamic-link library: either one can call. Whatever
calls has to use its its own instance handle.
--
TXR Programming Lanuage: http://nongnu.org/txr
Music DIY Mailing List: http://www.kylheku.com/diy
ADA MP-1 Mailing List: http://www.kylheku.com/mp1
Loading...