DirectInput under MS VS2008 CLI/C++

Started by
3 comments, last by Jerry.Mouse 12 years, 11 months ago
Hello,
I would like to replace MDX by SlimDX because MDX is very problematic. I need to read GamePad. I created new Form1 and add this lines to Form1_Load function. unfortunatelly compiler shows me errors: DirectInput is ambiguous symbol.

Joystick^ joystick;

JoystickState^ state = [color="#0000ff"][color="#0000ff"]gcnew JoystickState();

SlimDX::DirectInput^ di = [color="#0000ff"][color="#0000ff"]gcnew DirectInput();


Can anyone help how to correct this code.
Many thanks
Jerry

Advertisement
I'm not familiar with this, but:
compiler shows me errors[/quote]

It's normally very helpful if you say what the errors are.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

I am looking for replacement of this 15 lines of code. This code use ManagedDirectX CLI/C++ and I am looking fo SlimDX CLI/C++.


159 private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {

160

161 Microsoft::DirectX::DirectInput::DeviceList^ d;

162 d = Manager::GetDevices(Microsoft::DirectX::DirectInput::DeviceType::Joystick, Microsoft::DirectX::DirectInput::EnumDevicesFlags::AttachedOnly );

163

164 Device^ device;

165

166 for each(DeviceInstance^ di in Manager::GetDevices(DeviceClass::GameControl, EnumDevicesFlags::AttachedOnly) ){ // Manager::Devices ){

167

168 device = gcnew Device(di->InstanceGuid);

169

170 }// for

171

172 if (device == nullptr ){ // We couldn't find a joystick

173 Console::WriteLine("No gamepad");

174 }// if

175

176 device->SetDataFormat(DeviceDataFormat::Joystick);

177 device->SetCooperativeLevel(this, CooperativeLevelFlags::Background | CooperativeLevelFlags::NonExclusive);

178 device->Properties->AxisModeAbsolute = true;

179 device->Acquire();

180

181 JoystickState^ state = device->CurrentJoystickState;

182

183 while ( true ){

184

185 JoystickState^ state = device->CurrentJoystickState;

186 array <unsigned char,1>^ b = state->GetButtons();

187 array <int,1>^ ASlider = state->GetASlider();

188

189 }// while

190

191 device->Unacquire();

192

193 }// private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {

At this WEB page
http://slimdx.org/features.php
is written:
Native .NET 4 Binaries - SUPPORT / no problem
but If I want to use it I get this error:
C2882, 'DirectInput' Illegal use of namespace identifier in expression
I CAN NOT add SlimDX::DirectInput::DirectInput because CLI/C++ doesNOT see IT.




79 private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {

80

81 // Of course, I added SlimDX.dll to Properties / CommonProperties / AddNewReference

82 // Of course I added this two lines:

83 //

84 // using namespace SlimDX;

85 // using namespace SlimDX::DirectInput;

86 //

87

88 int numPOVs;

89 int SliderCount;

90

91 Joystick^ joystick;

92

93 JoystickState^ state = gcnew JoystickState();

94

95 SlimDX::DirectInput^ di = gcnew DirectInput(); // HERE is ERROR , C++ do not see SlimDX::DirectInput::DirectInput() class constuctor

96

97 }// private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)


yes this seems to be working, ... terrible.... ... I like FORTRAN


[color="#0000ff"][color="#0000ff"]private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {

[color="#0000ff"][color="#0000ff"]int numPOVs;

[color="#0000ff"][color="#0000ff"]int SliderCount;

[color="#008000"][color="#008000"]

JoystickState^ state;

SlimDX::DirectInput::Joystick^ joystick;



state = [color="#0000ff"][color="#0000ff"]gcnew JoystickState();

SlimDX::DirectInput::DirectInput^ dinput = [color="#0000ff"][color="#0000ff"]gcnew SlimDX::DirectInput::DirectInput();

[color="#0000ff"][color="#0000ff"]for [color="#0000ff"][color="#0000ff"]each (DeviceInstance^ device [color="#0000ff"][color="#0000ff"]in dinput->GetDevices(DeviceClass::GameController, DeviceEnumerationFlags::AttachedOnly)) {

[color="#008000"][color="#008000"]// create the device

Console::WriteLine([color="#a31515"][color="#a31515"]" {0} ",device->InstanceName);

[color="#0000ff"][color="#0000ff"]try

{

joystick = [color="#0000ff"][color="#0000ff"]gcnew Joystick( dinput, device->InstanceGuid );

[color="#008000"][color="#008000"]

}

[color="#0000ff"][color="#0000ff"]catch( ... ) [color="#008000"][color="#008000"]

{

Console::WriteLine([color="#a31515"][color="#a31515"]"No Gamepad"); [color="#008000"][color="#008000"]//

[color="#0000ff"][color="#0000ff"]delete( state );

[color="#0000ff"][color="#0000ff"]delete( dinput );

[color="#0000ff"][color="#0000ff"]return;

}

}[color="#008000"][color="#008000"]// for



[color="#008000"][color="#008000"]

joystick->Acquire();

[color="#0000ff"][color="#0000ff"]array <[color="#0000ff"][color="#0000ff"]bool,1>^ b;

[color="#0000ff"][color="#0000ff"]while ( [color="#0000ff"][color="#0000ff"]true ){



[color="#008000"][color="#008000"]//Application::DoEvents();

state = joystick->GetCurrentState(); [color="#008000"][color="#008000"]//GetCurrentState();

[color="#0000ff"][color="#0000ff"]if ( SlimDX::Result::Last.IsFailure == [color="#0000ff"][color="#0000ff"]true )

[color="#0000ff"][color="#0000ff"]return;

[color="#008000"][color="#008000"]//UpdateUI();

b = state->GetButtons();

Console::WriteLine([color="#a31515"][color="#a31515"]" {0} {1} {2} | {3} {4} {5} {6} {7} {8} {9} {10} ", state->X, state->Y, state->RotationZ, b[0], b[1], b[2],b[3], b[4], b[5],b[6], b[7] );

[color="#0000ff"][color="#0000ff"]if ( b[0] == [color="#0000ff"][color="#0000ff"]true ){

[color="#0000ff"][color="#0000ff"]break;

}[color="#008000"][color="#008000"]// if



}[color="#008000"][color="#008000"]// while

joystick->Unacquire();





[color="#0000ff"][color="#0000ff"]delete( joystick );

[color="#0000ff"][color="#0000ff"]delete( state );







}[color="#008000"][color="#008000"]// private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)

This topic is closed to new replies.

Advertisement