Target: Find a possibility to have a fully assignable joystick in a .NET² flight simulator, i.e. you can pick any available joystick-axis for any lever in the game.
Pass No1: Managed DirectInput V2.0 lacks buffered device data retrieval, so there is no way to extract abitrary axes from the device state. It is simply not possible except hard-coded device state look-ups.
Pass No2: It is obvious, that mixing managed DirectInput V1.0 with the other managed DirectX V2.0 components is a bad idea.
=> Write my own managed version of DirectInput. CODENAME DirectlyInput ;).
Pass No3: Include the native DInput.h. C++/CLI should be capable of handling native C/C++ code. However, due to the new syntax, C++/CLI cannot handle some constructs like "typedef interface ..." which is definied in some sub-headers that are related to COM. Unfortunately, the DirectInput header relies on the COM definitions in order to expose the DirectInput interfaces to COM. To make it short: I am unable to include DInput.h without tons of compiler errors. However, I think I can use the switch "/clr:oldSyntax" - with this switch, DInput.h seems to compile flawless. But I am not sure, if I am willing to go back to the
__syntax. Maybe I give this a try later.
Pass No4: Go with PInvoke/COM. Well, it was unexpectedly difficult to find helpful information. After hours of searching, I found out about useful stuff such as
ComImportAttribute,
GuidAttribute, and
InterfaceTypeAttribute, and that I could utilize GUIDs from the DInput.h header. After even more hours of painful trying and looking at freakin' error codes from the deepest deepness of kernel32, I even managed it to create an instance of the DirectInput8 class and cast it to the DirectInput8 interface using reflection. However, I never managed it to call any methods of this interface. After even more hours of trying and testing some modifications, I gave up.
Pass No5: What I personally don't understand - DirectX is said to be based on COM. A look at the header files seems to confirm this. But why can't I simply insert any DX-DLL as COM-Component in the VS-References page?
Pass No6: #import DInput8.dll should work perfectly, but for some reason, it produces the same kind of errors like including DInput.h
Pass No7: The 7th approach seemed to be promising at first, but it didn't work out. Maybe you find it amusing:
So, how to get access to a COM-API, that is not really exposed as a COM-DLL? Well, I talk about DirectInput, and DirectInput has not been updated since DirectX8. DirectX8 *HAS* a type-libarary for the ancient VB6, when there was no such thing such as MDX.
This type-library looked like the rescue for me. I could convert this type-library using "tlbimp.exe" to a *real* .NET-assembly. Then, I could disassemble this .NET-assembly back to IL-code using "ildasm.exe". This actually worked; I had a buch of class definitions in my .NET-wonderland. This IL-code file was something like 16k lines long. I removed something like 3/4 non-DirectInput stuff from this file, and after re-inserting the assembly-info, DxGUID, POINT, and RECT - which have been accidentally deleted ;) - this file - with DirectInput only definitions - truly compiled back to a .NET-assembly using "ilasm.exe". This .NET-assembly could seriously be added as reference in the VS-References without any problem, and this assembly only contained DirectInput definitions - I could see that in the class browser. Honestly, that made me proud ;).
Well, in the end, .NET could not really use these classes without throwing exceptions - I guess it was still nothing more than ancient VB6 class definitions. So this approach didn't work out as well.
A.R.G.H.H.!.!.!.