Jump to content
  • Advertisement
Sign in to follow this  
weewun

xinput lnk error

This topic is 3785 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok, i am looking to get an xbox 360 controller working on the pc to code with. i have tried to create a class to encorporate the functions of xinput to make it easier to use, but i get a "LNK2001: unresolved external symbol _XinputGetState@8" error when i try to call the main function in it that updatres the state of the pad. the file compiles fine etc. and i can create a controll pad object, but when i try to call the CheckControllerStatus() function it comes up with this error. does anyone know what i am doing wrong? chers for any help. my .h file is shown below: ///////////////////////////////////////////// #include <Winerror.h> #include <windows.h> #include <XInput.h> // Defines XBOX controller API #pragma comment(lib, “XInput.lib”) // Library containing necessary 360 // functions // // // i do not know if this actually works yet because i have not had a chance to test it properly! // when i tried it at home i got a LNK error which the 'XInputGetState' // // // // // // class XBOX360CONTROLLER{ XINPUT_STATE state; // Data type that stores all the current states XINPUT_VIBRATION vibration; public: bool CheckControllerStatus() //updates controller state, and checks to see if a controller { //is plugged in (must be called every loop!) DWORD dwResult; // Used to store if a controller is connected // of a controller. ZeroMemory( &state, sizeof(XINPUT_STATE) ); // Zeros out the states of // the controller. // Get all the current states of controller 1 dwResult = XInputGetState( 0, &state ); //ERROR IS HERE // I THINK! //this bit sets the dead zone for the two analogue sticks :) if( (state.Gamepad.sThumbLX < XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE && state.Gamepad.sThumbLX > -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) && (state.Gamepad.sThumbLY < XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE && state.Gamepad.sThumbLY > -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) ) { state.Gamepad.sThumbLX = 0; state.Gamepad.sThumbLY = 0; } if( (state.Gamepad.sThumbRX < XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE && state.Gamepad.sThumbRX > -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) && (state.Gamepad.sThumbRY < XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE && state.Gamepad.sThumbRY > -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) ) { state.Gamepad.sThumbRX = 0; state.Gamepad.sThumbRY = 0; } //will make sure that the controller is connected, and returns true or false each time if( dwResult == ERROR_SUCCESS ) { // Controller is connected. return true;// } else { return false;// Controller is disconnected. } } int LeftTrigger(){ //returns the values of the left and right triggers if(state.Gamepad.bLeftTrigger && state.Gamepad.bLeftTrigger < XINPUT_GAMEPAD_TRIGGER_THRESHOLD) { return state.Gamepad.bLeftTrigger; } //returns a value between 0-255 } int RightTrigger(){ if(state.Gamepad.bRightTrigger && state.Gamepad.bRightTrigger < XINPUT_GAMEPAD_TRIGGER_THRESHOLD) { return state.Gamepad.bRightTrigger; } //returns a value between 0-255 } //for the 4 coloured buttons bool X(){if(state.Gamepad.wButtons & XINPUT_GAMEPAD_X) return true; else return false;} bool Y(){if(state.Gamepad.wButtons & XINPUT_GAMEPAD_Y) return true; else return false;} bool A(){if(state.Gamepad.wButtons & XINPUT_GAMEPAD_A) return true; else return false;} bool B(){if(state.Gamepad.wButtons & XINPUT_GAMEPAD_B) return true; else return false;} //for the D-pad bool Up(){if(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) return true; else return false;} bool Down(){if(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN) return true; else return false;} bool Left(){if(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) return true; else return false;} bool Right(){if(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) return true; else return false;} //shoulder buttons bool RightShoulder(){if(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) return true; else return false;} bool LeftShoulder(){if(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) return true; else return false;} //analogue sticks int RightStickX(){return state.Gamepad.sThumbRX;} //returns a valuse between -3768 and +3768 so be careful! int RightStickY(){return state.Gamepad.sThumbRY;} //returns a valuse between -3768 and +3768 so be careful! bool RightStickPressed(){if(state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) return true; else return false;} float LeftStickX(){return state.Gamepad.sThumbLX;} //returns a valuse between -3768 and +3768 so be careful! float LeftStickY(){return state.Gamepad.sThumbLY;} //returns a valuse between -3768 and +3768 so be careful! bool LeftStickPressed(){if(state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) return true; else return false;} //start and back buttons bool Start(){if(state.Gamepad.wButtons & XINPUT_GAMEPAD_START) return true; else return false;} bool Back(){if(state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) return true; else return false;} //for the rumble feature bool VibrateOn(int powerLeft, int powerRight){ if(powerLeft>0 && powerLeft<65535 && powerRight>0 && powerRight<65535){//vibration value must be between 0 and 65535 ZeroMemory( &vibration, sizeof(XINPUT_VIBRATION) ); //clear out the chuink of data to be safe vibration.wLeftMotorSpeed = powerLeft; // use any value between 0-65535 vibration.wRightMotorSpeed = powerRight; XInputSetState( 0, &vibration ); return true; } else return false; } void VibrateOff(){ //turns off the vibrations ZeroMemory( &vibration, sizeof(XINPUT_VIBRATION) ); //clear out the chunk of data to be safe vibration.wLeftMotorSpeed = 0; // use any value between 0-65535 vibration.wRightMotorSpeed = 0; XInputSetState( 0, &vibration ); } };

Share this post


Link to post
Share on other sites
Advertisement
OMG! posting a reply on the off chance anyone else has this error, but its bacuase i am a simpleton :( the line :

#pragma comment(lib, “XInput.lib”) // Library containing necessary 360

has the worng kind of " in it, but this was only a warning from the compiler (it had thw wrong kind becasue i copy/pasted it) so it should be :

#pragma comment(lib, "XInput.lib") // Library containing necessary 360

cheers to anyone who had a ponder over this :P

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!