summaryrefslogtreecommitdiffhomepage
path: root/StarsEx/NPClientWraps.cpp
blob: 92d5561798ee74f2a75dd420c659ab694012ec18 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// *******************************************************************************
// *
// * Module Name:
// *   NPClientWraps.cpp
// *
// * Software Engineer:
// *   Doyle Nickless - GoFlight Inc., for Eye Control Technology.
// *
// * Abstract:
// *   This module implements the wrapper code for interfacing to the NaturalPoint
// *   Game Client API.  Developers of client apps can include this module into
// *   their projects to simplify communication with the NaturalPoint software.
// *
// *   This is necessary since the NPClient DLL is run-time linked rather than
// *   load-time linked, avoiding the need to link a static library into the
// *   client program (only this module is needed, and can be supplied in source
// *   form.)
// *
// * Environment:
// *   User mode
// *
// *******************************************************************************
//
#include "Text.h"
#include "Types.h"

#include "NPClient.h"
#include "NPClientWraps.h"

/////////////
// Defines ///////////////////////////////////////////////////////////////////////
/////////////
//

/////////////////
// Global Data ///////////////////////////////////////////////////////////////////
/////////////////
//
PF_NP_REGISTERWINDOWHANDLE       gpfNP_RegisterWindowHandle = NULL;
PF_NP_UNREGISTERWINDOWHANDLE     gpfNP_UnregisterWindowHandle = NULL;
PF_NP_REGISTERPROGRAMPROFILEID   gpfNP_RegisterProgramProfileID = NULL;
PF_NP_QUERYVERSION               gpfNP_QueryVersion = NULL;
PF_NP_REQUESTDATA                gpfNP_RequestData = NULL;
PF_NP_GETSIGNATURE               gpfNP_GetSignature = NULL;
PF_NP_GETDATA                    gpfNP_GetData = NULL;
PF_NP_STARTCURSOR                gpfNP_StartCursor = NULL;
PF_NP_STOPCURSOR                 gpfNP_StopCursor = NULL;
PF_NP_RECENTER                     gpfNP_ReCenter = NULL;
PF_NP_STARTDATATRANSMISSION      gpfNP_StartDataTransmission = NULL;
PF_NP_STOPDATATRANSMISSION       gpfNP_StopDataTransmission = NULL;

HMODULE ghNPClientDLL = (HMODULE)NULL;

////////////////////////////////////////////////////
// NaturalPoint Game Client API function wrappers /////////////////////////////
////////////////////////////////////////////////////
//
NPRESULT __stdcall NP_RegisterWindowHandle( HWND hWnd  )
{
    NPRESULT result = NP_ERR_DLL_NOT_FOUND;

    if( NULL != gpfNP_RegisterWindowHandle )
    result = (*gpfNP_RegisterWindowHandle)( hWnd );

    return result;
} // NP_RegisterWindowHandle()


NPRESULT __stdcall NP_UnregisterWindowHandle()
{
    NPRESULT result = NP_ERR_DLL_NOT_FOUND;

    if( NULL != gpfNP_UnregisterWindowHandle )
    result = (*gpfNP_UnregisterWindowHandle)();

    return result;
} // NP_UnregisterWindowHandle()


NPRESULT __stdcall NP_RegisterProgramProfileID( unsigned short wPPID )
{
    NPRESULT result = NP_ERR_DLL_NOT_FOUND;

    if( NULL != gpfNP_RegisterProgramProfileID )
    result = (*gpfNP_RegisterProgramProfileID)( wPPID );

    return result;
} // NP_RegisterProgramProfileID()


NPRESULT __stdcall NP_QueryVersion( unsigned short* pwVersion )
{
    NPRESULT result = NP_ERR_DLL_NOT_FOUND;

    if( NULL != gpfNP_QueryVersion )
    result = (*gpfNP_QueryVersion)( pwVersion );

    return result;
} // NP_QueryVersion()


NPRESULT __stdcall NP_RequestData( unsigned short wDataReq )
{
    NPRESULT result = NP_ERR_DLL_NOT_FOUND;

    if( NULL != gpfNP_RequestData )
    result = (*gpfNP_RequestData)( wDataReq );

    return result;
} // NP_RequestData()

NPRESULT __stdcall NP_GetSignature( LPTRACKIRSIGNATURE pSignature )
{
    NPRESULT result = NP_ERR_DLL_NOT_FOUND;

    if( NULL != gpfNP_GetSignature )
    result = (*gpfNP_GetSignature)( pSignature );

    return result;
} // NP_GetSignature()


NPRESULT __stdcall NP_GetData( LPTRACKIRDATA pTID )
{
    NPRESULT result = NP_ERR_DLL_NOT_FOUND;

    if( NULL != gpfNP_GetData )
    result = (*gpfNP_GetData)( pTID );

    return result;
} // NP_GetData()


NPRESULT __stdcall NP_StartCursor()
{
    NPRESULT result = NP_ERR_DLL_NOT_FOUND;

    if( NULL != gpfNP_StartCursor )
    result = (*gpfNP_StartCursor)();

    return result;
} // NP_StartCursor()


NPRESULT __stdcall NP_StopCursor()
{
    NPRESULT result = NP_ERR_DLL_NOT_FOUND;

    if( NULL != gpfNP_StopCursor )
    result = (*gpfNP_StopCursor)();

    return result;
} // NP_StopCursor()


NPRESULT __stdcall NP_ReCenter()
{
    NPRESULT result = NP_ERR_DLL_NOT_FOUND;

    if( NULL != gpfNP_ReCenter )
    result = (*gpfNP_ReCenter)();

    return result;
} // NP_ReCenter()


NPRESULT __stdcall NP_StartDataTransmission()
{
    NPRESULT result = NP_ERR_DLL_NOT_FOUND;

    if( NULL != gpfNP_StartDataTransmission )
    result = (*gpfNP_StartDataTransmission)();

    return result;
} // NP_StartDataTransmission()


NPRESULT __stdcall NP_StopDataTransmission()
{
    NPRESULT result = NP_ERR_DLL_NOT_FOUND;

    if( NULL != gpfNP_StopDataTransmission )
    result = (*gpfNP_StopDataTransmission)();

    return result;
} // NP_StopDataTransmission()


//////////////////////////////////////////////////////////////////////////////
// NPClientInit() -- Loads the DLL and retrieves pointers to all exports
//
NPRESULT NPClient_Init( const char* csDLLPath )
{
    NPRESULT result = NP_OK;

    Text csNPClientDLLFullPath;

    if (csDLLPath && *csDLLPath)
    csNPClientDLLFullPath = Text(csDLLPath) + "\\";
    csNPClientDLLFullPath += "NPClient.dll";

    ghNPClientDLL = ::LoadLibrary( csNPClientDLLFullPath.data() );

    if (NULL != ghNPClientDLL) {
        // verify the dll signature
        gpfNP_GetSignature = (PF_NP_GETSIGNATURE)::GetProcAddress( ghNPClientDLL, "NP_GetSignature" );

        SIGNATUREDATA pSignature;
        SIGNATUREDATA verifySignature;
        // init the signatures
        strcpy_s(verifySignature.DllSignature, "precise head tracking\n put your head into the game\n now go look around\n\n Copyright EyeControl Technologies");
        strcpy_s(verifySignature.AppSignature, "hardware camera\n software processing data\n track user movement\n\n Copyright EyeControl Technologies");
        // query the dll and compare the results
        NPRESULT vresult = NP_GetSignature( &pSignature );
        if( vresult == NP_OK )
        {
            if ((strcmp(verifySignature.DllSignature,pSignature.DllSignature)==0)
                    && (strcmp(verifySignature.AppSignature,pSignature.AppSignature)==0))
            {
                result = NP_OK;

                // Get addresses of all exported functions
                gpfNP_RegisterWindowHandle     = (PF_NP_REGISTERWINDOWHANDLE)::GetProcAddress( ghNPClientDLL, "NP_RegisterWindowHandle" );
                gpfNP_UnregisterWindowHandle   = (PF_NP_UNREGISTERWINDOWHANDLE)::GetProcAddress( ghNPClientDLL, "NP_UnregisterWindowHandle" );
                gpfNP_RegisterProgramProfileID = (PF_NP_REGISTERPROGRAMPROFILEID)::GetProcAddress( ghNPClientDLL, "NP_RegisterProgramProfileID" );
                gpfNP_QueryVersion             = (PF_NP_QUERYVERSION)::GetProcAddress( ghNPClientDLL, "NP_QueryVersion" );
                gpfNP_RequestData              = (PF_NP_REQUESTDATA)::GetProcAddress( ghNPClientDLL, "NP_RequestData" );
                gpfNP_GetData                  = (PF_NP_GETDATA)::GetProcAddress( ghNPClientDLL, "NP_GetData" );
                gpfNP_StartCursor              = (PF_NP_STARTCURSOR)::GetProcAddress( ghNPClientDLL, "NP_StartCursor" );
                gpfNP_StopCursor               = (PF_NP_STOPCURSOR)::GetProcAddress( ghNPClientDLL, "NP_StopCursor" );
                gpfNP_ReCenter                   = (PF_NP_RECENTER)::GetProcAddress( ghNPClientDLL, "NP_ReCenter" );
                gpfNP_StartDataTransmission    = (PF_NP_STARTDATATRANSMISSION)::GetProcAddress( ghNPClientDLL, "NP_StartDataTransmission" );
                gpfNP_StopDataTransmission     = (PF_NP_STOPDATATRANSMISSION)::GetProcAddress( ghNPClientDLL, "NP_StopDataTransmission" );
            }
            else
            {
                result = NP_ERR_DLL_NOT_FOUND;
            }
        }
        else
        {
            result = NP_ERR_DLL_NOT_FOUND;
        }
    }
    else
    result = NP_ERR_DLL_NOT_FOUND;

    return result;

} // NPClient_Init()

//////////////////////////////////////////////////////////////////////////////