int main(int argc, _TCHAR* argv[])
{
	struct ControllerStruct
	{
		unsigned long eventCount; //event counter, increases with every controller event,
					  //but for some reason not by one.
		unsigned short up:1, down:1, left:1, right:1, start:1, back:1, l3:1, r3:1,
                       lButton:1, rButton:1, guideButton:1, unknown:1, aButton:1,
                       bButton:1, xButton:1, yButton:1; // button state bitfield
		unsigned char lTrigger;  //Left Trigger
		unsigned char rTrigger;  //Right Trigger
		short lJoyY;  //Left Joystick Y
		short lJoyx;  //Left Joystick X
		short rJoyY;  //Right Joystick Y 
		short rJoyX;  //Right Joystick X
	};
	//First create an HINSTANCE of the xinput1_3.dll.  Probably should use system variables to find it
	//but whatever.
	HINSTANCE hGetProcIDDLL = LoadLibrary("C:/Windows/System32/xinput1_3.dll");  //In Visual Studio replace this
	//HINSTANCE hGetProcIDDLL = LoadLibrary(L"C:/Windows/System32/xinput1_3.dll");  //With this

	//Get the address of ordinal 100.
	FARPROC lpfnGetProcessID = GetProcAddress(HMODULE(hGetProcIDDLL), (LPCSTR)100);

	//typedef the function. It takes an int and a pointer to a ControllerStruct and returns an error code
	//as an int.  it's 0 for no error and 1167 for "controller not present".  presumably there are others
	//but I never saw them.  It won't cause a crash on error, it just won't update the data.
	typedef int(__stdcall * pICFUNC)(int, ControllerStruct &);

	//Assign it to getControllerData for easier use
	pICFUNC getControllerData;
	getControllerData = pICFUNC(lpfnGetProcessID);
	
	//Create in an instance of the ControllerStruct
	ControllerStruct buttons;
	while(1) //Infinite polling loop
	{

		getControllerData(0, buttons);  //call the function with the controller number(zero based) and
						//the pointer to the ControllerStruct.
		ClearScreen();  //clear the screen
		std::cout << buttons.guideButton;  //simply access the variable like normal.  Easy peasy.
		Sleep(50);  //pause briefly so as not to spam the console
	}
	//in a real program you should release the dll by calling FreeLibrary(hGetProcIDDLL) to prevent memory
	//leaks, but since there's no way of cleanly exiting this program, I'm not sure where to put it
	
	return 0;
}
Esempio n. 2
0
int _tmain(int argc, _TCHAR* argv[])
{
  /* get handle to dll */ 
   HINSTANCE hGetProcIDDLL = LoadLibrary("E:\\SteamLibrary\\SteamApps\\common\\Arma 3\\@MFD\\MFD_Extension.dll"); 

   /* get pointer to the function in the dll*/ 
   FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL),"_RVExtension@12"); 
   if(lpfnGetProcessID == NULL)
   {
		DWORD lastError = GetLastError();
		std::cout << "General failure. GetLastError returned " << std::hex << lastError << ".";
   }
   /* 
      Define the Function in the DLL for reuse. This is just prototyping the dll's function. 
      A mock of it. Use "stdcall" for maximum compatibility. 
   */ 
   typedef void (__stdcall * pICFUNC)(char *, int,char*); 

   pICFUNC dllExtension; 
   dllExtension = pICFUNC(lpfnGetProcessID); 
   //-noPause -nosplash -mod=@CBA_A3;@JayArmA2Lib;@ACRE;@fhq_m4_a3;RH_pdw1.0;@fhq_accessories;@ac130x_a3;@MFD;@JS_JC_FA18 -showScriptErrors  "C:\Users\bonilann\Documents\Arma 3 - Other Profiles\annerajb\missions\mfdtest.Stratis\mission.sqm"
   /* The actual call to the function contained in the dll */ 
   char* output = new char[4096];
   memset(output,0,4096);
   dllExtension(output, 4096,"version"); 
   //output should be version#
   //
   dllExtension(output, 4096,"pack|81=0/80=0"); 
   Sleep(5000);
   while(1)
   {
		dllExtension(output, 4096,"pack|81=1/81=0/302=12.5000"); 
   }
   
   delete[] output;




   /* Release the Dll */ 
   FreeLibrary(hGetProcIDDLL); 
	return 0;
}