From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

DirectInput with LabWindows/CVI

Solved!
Go to solution

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.

 

0 Kudos
Message 1 of 5
(4,720 Views)

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 

0 Kudos
Message 2 of 5
(4,675 Views)
Hi Brendan, I just updated to CVI2013SP1, and it doesn't make a difference, I get the same error message - it's basically just the first line opening a session, verbatim from the Microsoft DirectX example. It does compile with VisualStudio 2012, as mention above, that was not a typo.
0 Kudos
Message 3 of 5
(4,508 Views)

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 

0 Kudos
Message 4 of 5
(4,442 Views)
Solution
Accepted by topic author atomcooler

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.

0 Kudos
Message 5 of 5
(4,436 Views)