FreeTrack Forum

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

RSS >  updated freetrack_c_interface.cpp, now compiles under vc2008
Lord_Nothing #1 14/03/2009 - 02h48

Class : Apprenti
Posts : 6
Registered on : 25/05/2008

Off line

its not 100% bug free but at least it works

-updated the struct
-renamed FTReportID to FTReportName on line 93
-commented out the break in the loop, this allows the program to keep if for some reason the struct failed to update, so any program built off it should be error-tolerant



/************************************************************************
*    freetrack_c_interface.c
*   
*  A simple command line application which reads the data from FreeTrack
*    using the FreeTrackClient.dll interface.
*
*    Assumes that a copy of the FreeTrackClient.dll is in the same folder,
*    thought this does not necessarily have to be the same folder as the
*    FreeTrack application itself.
*
*    Based on code from http://en.wikipedia.org/wiki/Dynamic-link_library
*
*    Alastair Moore, December 2007
*
************************************************************************/

//#include <iostream>
//#include <tchar.h>
#include <windows.h>
#include <stdio.h>
#include <conio.h>

typedef struct
{
    unsigned long int dataID;
    long int camWidth;
    long int camHeight;

    float yaw;
    float pitch;
    float roll;
    float x;
    float y;
    float z;

    float rawyaw;
    float rawpitch;
    float rawroll;
    float rawx;
    float rawy;
    float rawz;

    float x1;
    float y1;
    float x2;
    float y2;
    float x3;
    float y3;
    float x4;
    float y4;
}FreeTrackData;

// DLL function signatures
// These match those given in FTTypes.pas
// WINAPI is macro for __stdcall defined somewhere in the depths of windows.h
typedef bool (WINAPI *importGetData)(FreeTrackData * data);
typedef char *(WINAPI *importGetDllVersion)(void);
typedef void (WINAPI *importReportID)(int name);
typedef char *(WINAPI *importProvider)(void);


int main(int argc, char **argv)
{
        //declare imported function pointers
       importGetData getData;
        importGetDllVersion getDllVersion;
        importReportID    reportID;
        importProvider provider;

        // create variables for exchanging data with the dll
       FreeTrackData data;
        FreeTrackData *pData;
        pData = &data;
        char *pDllVersion;
        int name = 453;
        char *pProvider;


       // Load DLL file
       HINSTANCE hinstLib = LoadLibrary("FreeTrackClient.dll");
       if (hinstLib == NULL) {
               printf("ERROR: unable to load DLL\n");
               return 1;
       }
        else
        {
            printf("dll loaded\n");
        }

       // Get function pointers
       getData = (importGetData)GetProcAddress(hinstLib, "FTGetData");
        getDllVersion = (importGetDllVersion)GetProcAddress(hinstLib, "FTGetDllVersion");
        reportID = (importReportID)GetProcAddress(hinstLib, "FTReportName");
        provider = (importProvider)GetProcAddress(hinstLib, "FTProvider");

        // Check they are valid
       if (getData == NULL) {
               printf("ERROR: unable to find 'FTGetData' function\n");
              FreeLibrary(hinstLib);
               return 1;
       }
        if (getDllVersion == NULL){
                printf("ERROR: unable to find 'FTGetDllVersion' function\n");
              FreeLibrary(hinstLib);
               return 1;
        }
        if (reportID == NULL){
                printf("ERROR: unable to find 'FTReportID' function\n");
              FreeLibrary(hinstLib);
               return 1;
        }
        if (reportID == NULL){
                printf("ERROR: unable to find 'FTProvider' function\n");
              FreeLibrary(hinstLib);
               return 1;
        }

        //    Print the address of each function
        printf("FTGetData is at address: 0x%x\n",getData);
        printf("FTGetDllVersion is at address: 0x%x\n",getDllVersion);
        printf("FTReportID is at address: 0x%x\n",reportID);
        printf("FTProvider is at address: 0x%x\n",provider);

        //    Call each function and display result
        pDllVersion = getDllVersion();
        printf("Dll Version: %s\n", pDllVersion);

        pProvider = provider();
        printf("Provider: %s\n", pProvider);
       
        reportID(name);    //not sure what this does - I guess it tells the dll that I am using it.
       
        system("pause"); //wait till keyboard is pressed before entering main loop
        while( kbhit() != 1)
        {
            system("cls"); //clear screen
            if (getData(pData))
            {
                printf("Record ID: %d\n" , data.dataID);
                printf("Yaw: %5.2f\n" , data.yaw );
                printf("Pitch: %5.2f\n" , data.pitch );
                printf("Roll: %5.2f\n" , data.roll );
                printf("X: %5.2f\n" , data.x );
                printf("Y: %5.2f\n" , data.y );
                printf("Z: %5.2f\n" , data.z );
            }
            else
            {
                printf("Nothing returned from getData\n");
                //break;
            }
        }

       // Unload DLL file
       FreeLibrary(hinstLib);

        return 0;
}
babasior #2 20/03/2009 - 19h33

Webmaster (admin)
Class : Webmaster (admin)
Posts : 930
Registered on : 09/07/2007

Off line Www

Thanks for feedback !

for developpers only ....  :rolleyes:

not for me at all  ;D
Dor666 #3 01/06/2011 - 23h53

Class : Apprenti
Posts : 1
Registered on : 01/06/2011

Off line

Thanks for help. This code worked for me after removing the following line:

reportID(name))

It caused a crash "writing location blah blah"
Scythe #4 18/06/2011 - 16h36

Class : Apprenti
Posts : 15
Registered on : 29/09/2010

Off line

I've hacked together this code and the DCS headtracking interface, but I haven't got the time to get the compile environment set up. The source is here:

http://www.tjhowse.com/dcs/HeadTrackerDll.zip

No doubt it'll require some jiggery-pokery to get it to compile, but the fundimentals are there. This SHOULD result in a DLL that loads the freetrack DLL and act as a proxy between freetrack and DCS games.

--Scythe--

 >  Fast reply

Message

 >  Stats

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