summaryrefslogtreecommitdiffhomepage
path: root/faceAPI
diff options
context:
space:
mode:
authorWim Vriend <facetracknoir@gmail.com>2011-05-28 15:00:53 +0000
committerWim Vriend <facetracknoir@gmail.com>2011-05-28 15:00:53 +0000
commit555a75bf6740d66857f8b8dee1b30a0a10d8f2db (patch)
treeb74016f47cdfef12f4e352bae152510ace2d2545 /faceAPI
parent7357858cee1c39ad25f187db422cb4ba0335ed77 (diff)
Changed CreateFileMappingA function: Opens only
git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@86 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb
Diffstat (limited to 'faceAPI')
-rw-r--r--faceAPI/main.cpp73
1 files changed, 28 insertions, 45 deletions
diff --git a/faceAPI/main.cpp b/faceAPI/main.cpp
index aeb2cd50..31706f80 100644
--- a/faceAPI/main.cpp
+++ b/faceAPI/main.cpp
@@ -53,6 +53,7 @@ SMMemMap *pMemData;
HANDLE hSMMutex;
smEngineHeadPoseData new_head_pose;
bool stopCommand = false;
+bool ftnoirConnected = false;
//enums
enum GROUP_ID
@@ -370,10 +371,11 @@ void run()
//
// Process the command sent by FaceTrackNoIR.
//
- sprintf_s(msg, "Command: %d, \n", pMemData->command, pMemData->par_val_int);
- OutputDebugStringA(msg);
- std::cout << msg;
- if (pMemData) {
+ if (ftnoirConnected && (pMemData != 0)) {
+
+ sprintf_s(msg, "Command: %d, \n", pMemData->command, pMemData->par_val_int);
+ OutputDebugStringA(msg);
+ std::cout << msg;
//
//
@@ -431,19 +433,21 @@ void run()
// Destroy video display
THROW_ON_ERROR(smVideoDisplayDestroy(&video_display_handle));
- if ( pMemData != NULL ) {
- UnmapViewOfFile ( pMemData );
- }
-
- if (hSMMutex != 0) {
- CloseHandle( hSMMutex );
- }
- hSMMutex = 0;
-
- if (hSMMemMap != 0) {
- CloseHandle( hSMMemMap );
+ if (ftnoirConnected) {
+ if ( pMemData != NULL ) {
+ UnmapViewOfFile ( pMemData );
+ }
+
+ if (hSMMutex != 0) {
+ CloseHandle( hSMMutex );
+ }
+ hSMMutex = 0;
+
+ if (hSMMemMap != 0) {
+ CloseHandle( hSMMemMap );
+ }
+ hSMMemMap = 0;
}
- hSMMemMap = 0;
} // run()
@@ -498,48 +502,27 @@ bool SMCreateMapping()
//
// A FileMapping is used to create 'shared memory' between the faceAPI and FaceTrackNoIR.
+ // FaceTrackNoIR creates the mapping, this program only opens it.
+ // If it's not there: the program was apparently started by the user instead of FaceTrackNoIR...
//
- // Try to create a FileMapping to the Shared Memory.
- // If one already exists: close it.
- //
- hSMMemMap = CreateFileMappingA( INVALID_HANDLE_VALUE , 00 , PAGE_READWRITE , 0 ,
- sizeof( TFaceData ) + sizeof( HANDLE ) + 100,
- (LPCSTR) SM_MM_DATA );
-
- if ( hSMMemMap != 0 ) {
- OutputDebugString(_T("FTCreateMapping says: FileMapping Created!\n"));
- }
-
- if ( ( hSMMemMap != 0 ) && ( (long) GetLastError == ERROR_ALREADY_EXISTS ) ) {
- CloseHandle( hSMMemMap );
- hSMMemMap = 0;
- }
-
- //
- // Create a new FileMapping, Read/Write access
+ // Open an existing FileMapping, Read/Write access
//
hSMMemMap = OpenFileMappingA( FILE_MAP_ALL_ACCESS , false , (LPCSTR) SM_MM_DATA );
if ( ( hSMMemMap != 0 ) ) {
- OutputDebugString(_T("FTCreateMapping says: FileMapping Created again...\n"));
+ ftnoirConnected = true;
+ OutputDebugString(_T("FTCreateMapping says: FileMapping opened successfully...\n"));
pMemData = (SMMemMap *) MapViewOfFile(hSMMemMap, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(TFaceData));
if (pMemData != NULL) {
OutputDebugString(_T("FTCreateMapping says: MapViewOfFile OK.\n"));
pMemData->state = 0;
-// pMemData->handle = handle; // The game uses the handle, to send a message that the Program-Name was set!
}
hSMMutex = CreateMutexA(NULL, false, SM_MUTEX);
}
else {
- OutputDebugString(_T("Error creating Shared Memory for faceAPI\n"));
- cerr << "Error creating Shared Memory for faceAPI" << endl;
- return false;
+ OutputDebugString(_T("FTCreateMapping says: FileMapping not opened...FaceTrackNoIR not connected!\n"));
+ ftnoirConnected = false;
+ pMemData = 0;
}
- //if (pMemData != NULL) {
- // pMemData->data.DataID = 1;
- // pMemData->data.CamWidth = 100;
- // pMemData->data.CamHeight = 250;
- //}
-
return true;
}