FreeTrack Forum

Welcome, you're not connected. ( Log in - Register )

RSS >  Using FreeTrackClient.dll in C#?, Doesn't want to load the DLL one bit.
lowpass #1 18/04/2009 - 22h37

Class : Apprenti
Posts : 3
Registered on : 18/04/2009

Off line

I want to graft Freetrack-tracking into modified version of Johnny Lee's DesktopVR demo (I put in webcam support). Should be easy if I can get freetrack talking into C# space.

When I try add FreeTrackClient.dll as a resource in the C# (visual studio express C#), it claims it is not valid.

Is the client code missing something C# needs to hook into it? I'd be happy to do the work required if somebody can tell me approximately what that is.. :)

Cheers. Freetrack is a great project!
codeking #2 20/04/2009 - 10h23

Class : Apprenti
Posts : 5
Registered on : 02/03/2009

Off line

Have You tried to add it to resources or as reference ? I You want to get data from FT ie. You have to use P/Invoke, I did it lately so I can post simple C# code - give me a info on PM.
lowpass #3 20/04/2009 - 19h37

Class : Apprenti
Posts : 3
Registered on : 18/04/2009

Off line

I think I've figured out what's going on.
Some useful stuff &cd=1&hl=en&ct=clnk&gl=ca]here.

And here is the code.
http://www.geocities.com/giovanni.dicanio/temp/InteropTest1.zip


   #region Native C DLL Interop
   class FreeTrackClientDll
   {
       [StructLayout(LayoutKind.Sequential)]
       public struct FreeTrackData
       {
           public float yaw;
           public float pitch;
           public float roll;
           public float x;
           public float y;
           public float z;
           public int dataID;
       }

       [DllImport("FreeTrackClient.dll")]
       public static extern bool FTGetData(ref FreeTrackData data);

       [DllImport("FreeTrackClient.dll")]
       public static extern string FTGetDllVersion();

       [DllImport("FreeTrackClient.dll")]
       public static extern void FTReportID(Int32 name);

       [DllImport("FreeTrackClient.dll")]
       public static extern string FTProvider();
   }
   #endregion

   class InteropTest
   {
       static void Main(string[] args)
       {
           var data = new FreeTrackClientDll.FreeTrackData();
           if (!FreeTrackClientDll.FTGetData(ref data))
           {
               Console.WriteLine("FTGetData returned false.");
               return;
           }

           string dllVersion = FreeTrackClientDll.FTGetDllVersion();
           Console.WriteLine("DLL Version: " + dllVersion);

           string provider = FreeTrackClientDll.FTProvider();
           Console.WriteLine("Provider: " + provider);

           FreeTrackClientDll.FTReportID(100);
       }
   }
}
lowpass #4 23/04/2009 - 00h52

Class : Apprenti
Posts : 3
Registered on : 18/04/2009

Off line

Turns out what's above isn't quite right. I took a look at FTServer.pas and copied the data structure. What's below seems to report everything nicely.


      class FreeTrackClientDll
       {
       [StructLayout(LayoutKind.Sequential)]
       public struct FreeTrackData
       {
           public int dataid;
           public int camwidth, camheight;
           public Single Yaw, Pitch, Roll, X, Y, Z;
           public Single RawYaw, RawPitch, RawRoll;
           public Single RawX, RawY, RawZ;
           public Single x1, y1, x2, y2, x3, y3, x4, y4;          
       }
       [DllImport("FreeTrackClient.dll")]
       public static extern bool FTGetData(ref FreeTrackData data);

       [DllImport("FreeTrackClient.dll")]
       public static extern string FTGetDllVersion();

       [DllImport("FreeTrackClient.dll")]
       public static extern void FTReportID(Int32 name);

       [DllImport("FreeTrackClient.dll")]
       public static extern string FTProvider();

       }
       FreeTrackClientDll.FreeTrackData FreeTrackData;


Checking if the DLL loaded and reporting data.

               FreeTrackData =  new FreeTrackClientDll.FreeTrackData();
               if (!FreeTrackClientDll.FTGetData(ref FreeTrackData))
               {
                   MessageBox.Show("FTGetData returned false. FreeTrack likely not working.");
                   return;
               }


Using information from the wiimote.

               float X; // X-Axis movement
               FreeTrackClientDll.FTGetData(ref FreeTrackData); // Load data into the structure
               X = FreeTrackData.X;


Thanks everyone. Hope this is helpful in the future.
aparsons #5 20/04/2012 - 05h04

Class : Apprenti
Posts : 2
Registered on : 20/04/2012

Off line

You sweet sweet person you.  I'm pretty good with making a .Net program in VB and C#, but not so skilled in importing unmanaged "classic" code into a .Net program unless it is well documented what structures and variable types.  THIS is what I've been looking for the last week while I'm writing a HMD HUD program.

I just finished the prototype helmet 3point rig and have configured FreeTrack to work well, but am now trying to tie the x/y/z/pitch/yaw/roll data into the early stage of the software.

I may just write a demo program for the .Net users VB and C# just to take this the next step and help out this great program and its user base.
kobu #6 07/12/2012 - 08h06

Class : Apprenti
Posts : 1
Registered on : 04/12/2012

Off line

Thank You very much. It works fine. You made my day, Cheers  :D

 >  Fast reply

Message

 >  Stats

1 user(s) connected during the last 10 minutes (0 member(s) and 1 guest(s)).