C# / C Sharp Example

Post questions, comments and feedback to our 3Dconnexion Windows Development Team.

Moderator: Moderators

UtaSH
Moderator
Moderator
Posts: 3276
Joined: Mon Nov 27, 2006 10:34 am
Location: Munich, Germany
Contact:

Re: C# / C Sharp Example

Post by UtaSH » Wed Jan 21, 2015 5:41 am

I sent you the links.

Zoony
Posts: 7
Joined: Tue Jan 20, 2015 6:12 am

Re: C# / C Sharp Example

Post by Zoony » Sat Jan 24, 2015 1:03 am

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 ?

Zoony
Posts: 7
Joined: Tue Jan 20, 2015 6:12 am

Re: C# / C Sharp Example

Post by Zoony » Wed Jan 28, 2015 6:22 am

4 Days and no reply ?

LeifB
Posts: 8
Joined: Fri Jan 16, 2015 8:53 am

Re: C# / C Sharp Example

Post by LeifB » Thu Jan 29, 2015 11:31 am

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").

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;
        }
    }
You can then use it as follows, i.e. in your Form constructor:

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!

mijo
Posts: 1
Joined: Thu Jan 29, 2015 11:34 pm

Re: C# / C Sharp Example

Post by mijo » Thu Jan 29, 2015 11:40 pm

I'd like to get the C# sample as well

mbonk
Moderator
Moderator
Posts: 145
Joined: Mon Dec 04, 2006 4:06 am

Re: C# / C Sharp Example

Post by mbonk » Fri Jan 30, 2015 3:58 am

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.
Hi,

Can you post a full sample project which displays this behavior, please.

Markus

UtaSH
Moderator
Moderator
Posts: 3276
Joined: Mon Nov 27, 2006 10:34 am
Location: Munich, Germany
Contact:

Re: C# / C Sharp Example

Post by UtaSH » Fri Jan 30, 2015 9:25 am

mijo wrote:I'd like to get the C# sample as well
Links sent in a PM.

C.Müller
Posts: 1
Joined: Wed Feb 04, 2015 6:15 am

Re: C# / C Sharp Example

Post by C.Müller » Wed Feb 04, 2015 6:23 am

I'd also like to have the C# exsample. :)

UtaSH
Moderator
Moderator
Posts: 3276
Joined: Mon Nov 27, 2006 10:34 am
Location: Munich, Germany
Contact:

Re: C# / C Sharp Example

Post by UtaSH » Wed Feb 04, 2015 6:33 am

Links sent in PM.

alex77
Posts: 1
Joined: Fri Feb 06, 2015 12:37 am

Re: C# / C Sharp Example

Post by alex77 » Fri Feb 06, 2015 12:39 am

I'd like to get the C# sample as well.
I cannot to access ftp :(

EmilyC
Posts: 2
Joined: Mon Feb 09, 2015 3:22 am

Re: C# / C Sharp Example

Post by EmilyC » Mon Feb 09, 2015 3:27 am

Hi, I'd like to have the C# example too please.

UtaSH
Moderator
Moderator
Posts: 3276
Joined: Mon Nov 27, 2006 10:34 am
Location: Munich, Germany
Contact:

Re: C# / C Sharp Example

Post by UtaSH » Mon Feb 09, 2015 8:33 am

Links sent to both of you. :)

EmilyC
Posts: 2
Joined: Mon Feb 09, 2015 3:22 am

Re: C# / C Sharp Example

Post by EmilyC » Tue Feb 10, 2015 4:45 am

Thank you very much!

Phranky
Posts: 1
Joined: Thu Feb 12, 2015 5:36 am

Re: C# / C Sharp Example

Post by Phranky » Thu Feb 12, 2015 5:38 am

Hi,

can you please send me the C# sample code too.

Thanks!

ngomes
Moderator
Moderator
Posts: 1944
Joined: Mon Nov 27, 2006 7:22 am
Contact:

Re: C# / C Sharp Example

Post by ngomes » Thu Feb 12, 2015 7:24 am

Hi Phranky,
can you please send me the C# sample code too.
Sample source code is no longer available from the FTP server. Please contact 3Dconnexion'sAPI Support and they will assist with your request.

Locked