C# / C Sharp Example
Moderator: Moderators
Re: C# / C Sharp Example
I can build csMonitor to an exe with Visual Studio 2010 and run it on my Win7 64bit system no problem and my SpaceMouse Wirelss is read correctly, BUT . . .
I need it to run as a DLL for a plugin with my host application. I created a new project with a new form that has only one textbox and this loads okay from my application menu.
The problem is I get this error;
System.InvalidCastException: Unable to cast object of type 'TDxInput.Device' to type 'TDx.TDxInput.DeviceClass'.
And the culprit is the line indicated below that you should recognise from the csMonitor example; ( so it works if target is exe but not if dll )
private TDx.TDxInput.Sensor sensor;
private TDx.TDxInput.Keyboard keyboard;
private TDx.TDxInput.Device device;
private System.DateTime lastUpdate;
private bool isRunning;
public Form1()
{
InitializeComponent();
isRunning = false;
try
{
this.device = new TDx.TDxInput.Device(); // ****************** this line causes the problem
this.sensor = this.device.Sensor;
this.keyboard = this.device.Keyboard;
this.lastUpdate = System.DateTime.Now;
. . . etc.
Why ? and more importantly, what is the answer ?
I need it to run as a DLL for a plugin with my host application. I created a new project with a new form that has only one textbox and this loads okay from my application menu.
The problem is I get this error;
System.InvalidCastException: Unable to cast object of type 'TDxInput.Device' to type 'TDx.TDxInput.DeviceClass'.
And the culprit is the line indicated below that you should recognise from the csMonitor example; ( so it works if target is exe but not if dll )
private TDx.TDxInput.Sensor sensor;
private TDx.TDxInput.Keyboard keyboard;
private TDx.TDxInput.Device device;
private System.DateTime lastUpdate;
private bool isRunning;
public Form1()
{
InitializeComponent();
isRunning = false;
try
{
this.device = new TDx.TDxInput.Device(); // ****************** this line causes the problem
this.sensor = this.device.Sensor;
this.keyboard = this.device.Keyboard;
this.lastUpdate = System.DateTime.Now;
. . . etc.
Why ? and more importantly, what is the answer ?
Re: C# / C Sharp Example
Hey folks,
The examples from UtaSH are great but they reply on WPF. If you're using plain C# and Windows Forms (like me), here's a little trick to make it easy to hook up to your Windows Forms code as a message handler and so on. It's a helper class as follows. (You could also in theory extend their class, but they marked it as "sealed").
You can then use it as follows, i.e. in your Form constructor:
Where the event handlers are as previously defined (see examples). And that's it!
Enjoy!
The examples from UtaSH are great but they reply on WPF. If you're using plain C# and Windows Forms (like me), here's a little trick to make it easy to hook up to your Windows Forms code as a message handler and so on. It's a helper class as follows. (You could also in theory extend their class, but they marked it as "sealed").
Code: Select all
class Mouse3DHelper : IMessageFilter
{
public _3DxMouse._3DxMouse my3DxMouse { get; private set; } // This is the class from the examples
public int NumberOf3DxMice { get; private set; }
public Mouse3DHelper(IntPtr Handle)
{
// Connect to Raw Input & find devices
my3DxMouse = new _3DxMouse._3DxMouse(Handle);
NumberOf3DxMice = my3DxMouse.EnumerateDevices();
if (NumberOf3DxMice > 0)
{
// Capture Window events
Application.AddMessageFilter(this);
}
}
public bool PreFilterMessage(ref Message m)
{
if (my3DxMouse != null)
{
my3DxMouse.ProcessMessage(m);
}
return false;
}
}
Code: Select all
Mouse3DHelper helper = new Mouse3DHelper(this.Handle);
helper.my3DxMouse.ButtonEvent += my3DxMouse_ButtonEvent;
helper.my3DxMouse.MotionEvent += my3DxMouse_MotionEvent;
Where the event handlers are as previously defined (see examples). And that's it!
Enjoy!
Re: C# / C Sharp Example
I'd like to get the C# sample as well
Re: C# / C Sharp Example
Hi,Zoony wrote:I can build csMonitor to an exe with Visual Studio 2010 and run it on my Win7 64bit system no problem and my SpaceMouse Wirelss is read correctly, BUT . . .
I need it to run as a DLL for a plugin with my host application.
Can you post a full sample project which displays this behavior, please.
Markus
Re: C# / C Sharp Example
Links sent in a PM.mijo wrote:I'd like to get the C# sample as well
Uta
3Dconnexion
3Dconnexion
Re: C# / C Sharp Example
I'd also like to have the C# exsample.
Re: C# / C Sharp Example
I'd like to get the C# sample as well.
I cannot to access ftp
I cannot to access ftp
Re: C# / C Sharp Example
Hi, I'd like to have the C# example too please.
Re: C# / C Sharp Example
Hi,
can you please send me the C# sample code too.
Thanks!
can you please send me the C# sample code too.
Thanks!
Re: C# / C Sharp Example
Hi Phranky,
Sample source code is no longer available from the FTP server. Please contact 3Dconnexion'sAPI Support and they will assist with your request.can you please send me the C# sample code too.