public int StartAndRegisterFFB(AFFBManager ffb) { // Start FFB #if FFB if (Joystick.IsDeviceFfb(joyID)) { #if false // obsolete bool Ffbstarted = Joystick.FfbStart(joyID); if (!Ffbstarted) { Console.WriteLine("Failed to start FFB on vJoy device number {0}.", joyID); Console.ReadKey(); return(-3); } else { Console.WriteLine("Started FFB on vJoy device number {0} - OK", joyID); } #endif // Register Generic callback function // At this point you instruct the Receptor which callback function to call with every FFB packet it receives // It is the role of the designer to register the right FFB callback function // Note from me: // Warning: the callback is called in the context of a thread started by vJoyInterface.dll // when opening the joystick. This thread blocks upon a new system event from the driver. // It is perfectly ok to do some work in it, but do not overload it to avoid // loosing/desynchronizing FFB packets from the third party application. FFBReceiver.RegisterBaseCallback(Joystick, joyID, ffb); } #endif // FFB return(0); }
public FfbInterface(TesterForm dialog) { dlg = dialog; joystick = dialog.joystick; // FFB #pragma warning disable 0618 if (!joystick.FfbStart(id)) { throw new Exception(String.Format("Failed to start Forcefeedback on device {0}", id)); } #pragma warning restore 0618 // Convert Form to pointer and pass it as user data to the callback function GCHandle h = GCHandle.Alloc(dialog); IntPtr parameter = (IntPtr)h; // joystick.FfbRegisterGenCB(OnEffect, parameter); joystick.FfbRegisterGenCB(OnEffectObj, dialog); }