summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_protocol_sc
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2013-07-05 00:19:03 +0200
committerStanislaw Halik <sthalik@misaki.pl>2013-07-05 00:19:03 +0200
commit30fe442f524e91639e9d5f27d86c2edf290ab9c0 (patch)
treed5ec865995f07ef419a2c13afaa087ad4f03e599 /ftnoir_protocol_sc
parent2b7252c20154628a463efe6f1fa640ac9be9262e (diff)
Robustify SimConnect protocol
- No longer leaks library handle/address space - Use an activation context instead of hardcoding probable DLL filenames
Diffstat (limited to 'ftnoir_protocol_sc')
-rw-r--r--ftnoir_protocol_sc/ftnoir-protocol-sc.rc4
-rw-r--r--ftnoir_protocol_sc/ftnoir_protocol_sc.cpp56
-rw-r--r--ftnoir_protocol_sc/ftnoir_protocol_sc.h12
-rw-r--r--ftnoir_protocol_sc/scserver.manifest5
-rw-r--r--ftnoir_protocol_sc/simconnect.apsbin1264 -> 0 bytes
5 files changed, 46 insertions, 31 deletions
diff --git a/ftnoir_protocol_sc/ftnoir-protocol-sc.rc b/ftnoir_protocol_sc/ftnoir-protocol-sc.rc
index 3838d941..3b43715e 100644
--- a/ftnoir_protocol_sc/ftnoir-protocol-sc.rc
+++ b/ftnoir_protocol_sc/ftnoir-protocol-sc.rc
@@ -1,2 +1,2 @@
-#include "winuser.h"
-2 RT_MANIFEST scserver.manifest \ No newline at end of file
+#include <winuser.h>
+142 RT_MANIFEST scserver.manifest \ No newline at end of file
diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp
index 3cc25be4..a178e009 100644
--- a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp
+++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp
@@ -54,6 +54,8 @@ float FTNoIR_Protocol::prevSCRotX = 0.0f;
float FTNoIR_Protocol::prevSCRotY = 0.0f;
float FTNoIR_Protocol::prevSCRotZ = 0.0f;
+static QLibrary SCClientLib;
+
/** constructor **/
FTNoIR_Protocol::FTNoIR_Protocol()
{
@@ -139,7 +141,7 @@ PDWORD_PTR MsgResult = 0;
// prevRotY = virtRotY;
// prevRotZ = virtRotZ;
- if SUCCEEDED(simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, NULL)) {
+ if (SUCCEEDED(simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, NULL))) {
qDebug() << "FTNoIR_Protocol::sendHeadposeToGame() says: Dispatching";
}
else {
@@ -153,25 +155,39 @@ PDWORD_PTR MsgResult = 0;
//
bool FTNoIR_Protocol::checkServerInstallationOK()
{
- qDebug() << "SCCheckClientDLL says: Starting Function";
-
- const char* simconnect_paths[] = {
- "SimConnect.DLL",
- "C:\\Windows\\WinSxS\\x86_microsoft.flightsimulator.simconnect_67c7c14424d61b5b_10.0.60905.0_none_dd92b94d8a196297\\SimConnect.DLL",
- "C:\\Windows\\WinSxS\\x86_microsoft.flightsimulator.simconnect_67c7c14424d61b5b_10.0.61242.0_none_e079b46b85043c20\\SimConnect.DLL",
- "C:\\Windows\\WinSxS\\x86_microsoft.flightsimulator.simconnect_67c7c14424d61b5b_10.0.61259.0_none_55f5ecdc14f60568\\SimConnect.DLL",
- NULL
- };
-
- for (int i = 0; simconnect_paths[i]; i++)
+ HANDLE hactctx = INVALID_HANDLE_VALUE;
+ ULONG_PTR actctx_cookie = NULL;
+ if (!SCClientLib.isLoaded())
{
- SCClientLib.setFileName(simconnect_paths[i]);
+ ACTCTXA actx = {0};
+ actx.cbSize = sizeof(ACTCTXA);
+ actx.lpResourceName = MAKEINTRESOURCEA(142);
+ actx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
+ QString path = QCoreApplication::applicationDirPath() + "/opentrack-proto-simconnect.dll";
+ QByteArray name = QFile::encodeName(path);
+ actx.lpSource = name.constData();
+ hactctx = CreateActCtxA(&actx);
+ actctx_cookie = 0;
+ if (hactctx != INVALID_HANDLE_VALUE) {
+ if (!ActivateActCtx(hactctx, &actctx_cookie)) {
+ qDebug() << "SC: can't set win32 activation context" << GetLastError();
+ ReleaseActCtx(hactctx);
+ hactctx = INVALID_HANDLE_VALUE;
+ }
+ } else {
+ qDebug() << "SC: can't create win32 activation context";
+ }
+
+ qDebug() << "SCCheckClientDLL says: Starting Function";
+
+ SCClientLib.setFileName("SimConnect.DLL");
+
if (!SCClientLib.load()) {
- qDebug() << "SCCheckClientDLL says: Error loading SimConnect DLL";
- qDebug() << SCClientLib.errorString();
- continue;
+ qDebug() << "SC load" << SCClientLib.errorString();
+ return false;
}
- break;
+ } else {
+ qDebug() << "SimConnect already loaded";
}
//
@@ -226,6 +242,12 @@ bool FTNoIR_Protocol::checkServerInstallationOK()
}
qDebug() << "FTNoIR_Protocol::checkServerInstallationOK() says: SimConnect functions resolved in DLL!";
+
+ if (hactctx != INVALID_HANDLE_VALUE)
+ {
+ DeactivateActCtx(0, actctx_cookie);
+ ReleaseActCtx(hactctx);
+ }
return true;
}
diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.h b/ftnoir_protocol_sc/ftnoir_protocol_sc.h
index 62210d32..c22c36c7 100644
--- a/ftnoir_protocol_sc/ftnoir_protocol_sc.h
+++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.h
@@ -30,7 +30,6 @@
#ifndef INCLUDED_SCSERVER_H
#define INCLUDED_SCSERVER_H
#include "facetracknoir/global-settings.h"
-
//
// Prevent the SimConnect manifest from being merged in the application-manifest
// This is necessary to run FaceTrackNoIR on a PC without FSX
@@ -38,11 +37,11 @@
#define SIMCONNECT_H_NOMANIFEST
#define _WIN32_WINNT 0x0502
-#include "Windows.h"
-#include "SimConnect.h"
+#include <Windows.h>
+#include <SimConnect.h>
-#include "..\ftnoir_protocol_base\ftnoir_protocol_base.h"
-#include "ui_FTNoIR_SCcontrols.h"
+#include <..\ftnoir_protocol_base\ftnoir_protocol_base.h>
+#include <ui_FTNoIR_SCcontrols.h>
#include <QMessageBox>
#include <QSettings>
#include <QLibrary>
@@ -92,7 +91,6 @@ public:
private:
// Private properties
QString ProgramName;
- QLibrary SCClientLib;
static float virtSCPosX;
static float virtSCPosY;
@@ -121,7 +119,7 @@ private:
importSimConnect_AddClientEventToNotificationGroup simconnect_addclienteventtonotificationgroup;
importSimConnect_SetNotificationGroupPriority simconnect_setnotificationgrouppriority;
- static HANDLE hSimConnect; // Handle to SimConnect
+ static HANDLE hSimConnect; // Handle to SimConnect
static void CALLBACK processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext);
void loadSettings();
};
diff --git a/ftnoir_protocol_sc/scserver.manifest b/ftnoir_protocol_sc/scserver.manifest
index 19b123ba..6d6a8edb 100644
--- a/ftnoir_protocol_sc/scserver.manifest
+++ b/ftnoir_protocol_sc/scserver.manifest
@@ -5,9 +5,4 @@
<assemblyIdentity type='win32' name='Microsoft.FlightSimulator.SimConnect ' version='10.0.60905.0' processorArchitecture='x86' publicKeyToken='67c7c14424d61b5b' />
</dependentAssembly>
</dependency>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50608.0' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
- </dependentAssembly>
- </dependency>
</assembly>
diff --git a/ftnoir_protocol_sc/simconnect.aps b/ftnoir_protocol_sc/simconnect.aps
deleted file mode 100644
index 89c5a65a..00000000
--- a/ftnoir_protocol_sc/simconnect.aps
+++ /dev/null
Binary files differ