04-25-2014 04:38 PM
Hi,
I'm trying to use DirectInput to get position data from a USB joystick in LabWindows/CVI. CVI 2013 comes with the headers and libs for direct input in its sdk subfolder, and the DirectX SDK comes with a really simple example.
However, already the first step of opening creating a directinput handle fails to compile - this is basically copied verbatim from the directInput documentation or the joystick example provided with the DirectX SDK.
#include <ansi_c.h>
#define DIRECTINPUT_VERSION 0x0800
#include "dinput.h"
int main (int argc, char *argv[])
{
LPDIRECTINPUT8 di;
HRESULT hr;
hr = hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION, IID_IDirectInput8, ( VOID** )&di, NULL );
return 0;
}
60, 42 error: passing 'const GUID' (aka 'const struct _GUID') to parameter of incompatible type 'const IID *' (aka 'const struct _GUID *')
18, 1 In file included from c:\Users\tpaprotta\Documents\National Instruments\CVI\Command-line Application.c:18:
"dinput.h"(2682,83) c:\program files (x86)\national instruments\cvi2013\sdk\include\dinput.h:2682:83: note: passing argument to parameter 'riidltf' here
The same code compiles without issues under Visual Studio 2012.
Solved! Go to Solution.
04-29-2014 04:14 PM
Greetings,
I assume you mean works in LabWindows/CVI 2012? Also, do you have the latest patch for CVI 2013?
Regards,
Brandon V.
Applications Engineer
National Instruments
06-05-2014 03:50 PM
06-12-2014 02:43 PM
It looks like this example may have been written for C++ instead of C. This might be why it runs in Visual Studio and not CVI. Can you investigate this?
Regards,
Brandon V.
Applications Engineer
National Instruments
06-12-2014 03:59 PM - edited 06-12-2014 04:01 PM
So there is / was a number of issues. Yes, the example in question is C++, so instead of calling
DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION, IID_IDirectInput8, ( VOID** )&di, NULL );
one has to call
DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION, &IID_IDirectInput8, ( VOID** )&di, NULL );
(IID_IDirectInput8 is defined differently depending on whether C or C++ invokes it).
However, if one makes that change, the symbol _IID_IDirectInput8 can't be found. The symbol is not in dinput8.lib (which is included with CVI), but rather in dxguid.lib (which I couldn't find in the NI folders). It is distributed with the DirectX SDK - so I'm linking against that now. I'm curious, however, why NI would distribute dinput8.lib / dll and not other requisite libraries, which seem to be needed to use them.