summaryrefslogtreecommitdiffhomepage
path: root/FreeTrackClient/FTClient.cpp
blob: d48a2c286914576ac028fc78142be0297b8f2348 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**   @file  
     @brief  
*/
#include "FTClient.h"




  static double/*?*/ const FT_PROGRAMID = "FT_ProgramID";


  HANDLE hFTMemMap;
  PFreetrackData FTData;
  unsigned long lastDataID;
  PHandle FTHandle;
  PAnsiChar FTProgramName;
  HANDLE FTMutex;


bool FTGetData(PFreetrackData data)
{   bool result;
  result = false;
  if(  !! FTData ) {
    if(  FTData->DataID != lastDataID ) {
      Move( FTData/*?*/^ , data/*?*/^ , SizeOf( TFreetrackData ) );
      lastDataID = FTData->DataID;
      result = true;
    }
  } else
    OpenMapping;
return result;
}


void FTReportName(PAnsiChar name)
{
  unsigned long MsgResult;

  if(  OpenMapping && ( WaitForSingleObject( FTMutex , 100 ) == WAIT_OBJECT_0 ) ) {
    Move( name/*?*/^ , FTProgramName/*?*/^ , 100 );
    SendMessageTimeout( FTHandle/*?*/^ , RegisterWindowMessage( FT_PROGRAMID ) , 0 , 0 , 0 , 2000 , MsgResult );
    ReleaseMutex( FTMutex );
  }
}


char* FTGetDllVersion()
{   char* result;
  unsigned long VerInfoSize;
  Pointer VerInfo;
  unsigned long VerValueSize;
  PVSFixedFileInfo VerValue;
  unsigned long Dummy;
  std::string verString;
  char* dllName[100];

  result = "";
  GetModuleFilename( HInstance , &dllName , 100 );
  VerInfoSize = GetFileVersionInfoSize( &dllName , Dummy );
  if(  !( VerInfoSize == 0 ) ) {
    GetMem( VerInfo , VerInfoSize );
    GetFileVersionInfo( &dllName , 0 , VerInfoSize , VerInfo );
    VerQueryValue( VerInfo , "\\" , Pointer( VerValue ) , VerValueSize );
    /*?*//* WITH  VerValue/*?*/^ */
    {
      verString = IntToStr( dwFileVersionMS >> 16 );
      verString = verString + "." + IntToStr( dwFileVersionMS && 0xFFFF );
      verString = verString + "." + IntToStr( dwFileVersionLS >> 16 );
      verString = verString + "." + IntToStr( dwFileVersionLS && 0xFFFF );
      result = char*( verString );
    }
    FreeMem( VerInfo , VerInfoSize );
  }
return result;
}


char* FTProvider()
{   char* result;
  result = FREETRACK;return result;
}





bool OpenMapping()
{   bool result;
  if(  hFTMemMap != 0 )
    result = true;else {
    hFTMemMap = OpenFileMapping( FILE_MAP_ALL_ACCESS , false , FT_MM_DATA );
    if(  ( hFTMemMap != 0 ) ) {
      FTData = MapViewOfFile( hFTMemMap , FILE_MAP_ALL_ACCESS , 0 , 0 , SizeOf( TFreetrackData ) + SizeOf( HANDLE ) + 100 );
      FTHandle = Pointer( unsigned long( FTData ) + SizeOf( TFreetrackData ) );
      FTProgramName = Pointer( unsigned long( FTHandle ) + SizeOf( HANDLE ) );
      FTMutex = OpenMutex( MUTEX_ALL_ACCESS , false , FREETRACK_MUTEX );
    }
    result = !! FTData;
  }
return result;
}


void DestroyMapping()
{
  if(  FTData != 00 ) {
    UnMapViewofFile( FTData );
    FTData = 00;
  }

  CloseHandle( FTMutex );
  CloseHandle( hFTMemMap );
  hFTMemMap = 0;
}




//END