So i’m working on a Flight Simulator add-on and as you probably know the sdk is only available in C++ and C#. The problem is that i’m working on the UI with Javascript and NodeJS. I’m currenlty blocked on a bug that I don’t know how to fix. So basically I’ve downloaded the “node-gyp” package to be able to run C++ code directly into my NodeJS program, and the app isn’t working due to what I thing missing dependencies, here is my code :
portal.js
<code>const simConnect = require('./build/Release/simconnect');
function onSimulatorStart() {
console.log('Simulator has started!');
simConnect.initializeSimConnect(onSimulatorStart);
<code>const simConnect = require('./build/Release/simconnect');
function onSimulatorStart() {
console.log('Simulator has started!');
}
simConnect.initializeSimConnect(onSimulatorStart);
</code>
const simConnect = require('./build/Release/simconnect');
function onSimulatorStart() {
console.log('Simulator has started!');
}
simConnect.initializeSimConnect(onSimulatorStart);
simconnect.cpp
HANDLE hSimConnect = NULL;
Persistent<Function> callback;
void CALLBACK MyDispatchProcRD(SIMCONNECT_RECV* pData, DWORD cbData, void* pContext) {
if (pData->dwID == SIMCONNECT_RECV_ID_EVENT) {
SIMCONNECT_RECV_EVENT* evt = (SIMCONNECT_RECV_EVENT*)pData;
if (evt->uEventID == EVENT_SIM_START) {
void onSimulatorStart() {
Isolate* isolate = Isolate::GetCurrent();
HandleScope handleScope(isolate);
Local<Function> cb = Local<Function>::New(isolate, callback);
cb->Call(isolate->GetCurrentContext(), Null(isolate), 0, nullptr).ToLocalChecked();
void InitializeSimConnect(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
if (!args[0]->IsFunction()) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Callback must be a function").ToLocalChecked()));
Local<Function> cb = Local<Function>::Cast(args[0]);
callback.Reset(isolate, cb);
if (SUCCEEDED(SimConnect_Open(&hSimConnect, "SimConnect Test", NULL, 0, 0, 0))) {
std::cout << "Connected to Flight Simulator!" << std::endl;
SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_SIM_START, "SimStart");
SimConnect_CallDispatch(hSimConnect, MyDispatchProcRD, NULL);
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Unable to connect to Flight Simulator").ToLocalChecked()));
void Initialize(Local<Object> exports) {
NODE_SET_METHOD(exports, "initializeSimConnect", InitializeSimConnect);
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
<code>#include <node.h>
#include <windows.h>
#include <SimConnect.h>
#include <iostream>
#include <thread>
using namespace v8;
HANDLE hSimConnect = NULL;
Persistent<Function> callback;
enum EVENT_ID {
EVENT_SIM_START
};
void onSimulatorStart();
void CALLBACK MyDispatchProcRD(SIMCONNECT_RECV* pData, DWORD cbData, void* pContext) {
if (pData->dwID == SIMCONNECT_RECV_ID_EVENT) {
SIMCONNECT_RECV_EVENT* evt = (SIMCONNECT_RECV_EVENT*)pData;
if (evt->uEventID == EVENT_SIM_START) {
onSimulatorStart();
}
}
}
void onSimulatorStart() {
Isolate* isolate = Isolate::GetCurrent();
HandleScope handleScope(isolate);
Local<Function> cb = Local<Function>::New(isolate, callback);
cb->Call(isolate->GetCurrentContext(), Null(isolate), 0, nullptr).ToLocalChecked();
}
void InitializeSimConnect(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
if (!args[0]->IsFunction()) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Callback must be a function").ToLocalChecked()));
return;
}
Local<Function> cb = Local<Function>::Cast(args[0]);
callback.Reset(isolate, cb);
if (SUCCEEDED(SimConnect_Open(&hSimConnect, "SimConnect Test", NULL, 0, 0, 0))) {
std::cout << "Connected to Flight Simulator!" << std::endl;
SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_SIM_START, "SimStart");
std::thread([]() {
while (true) {
SimConnect_CallDispatch(hSimConnect, MyDispatchProcRD, NULL);
Sleep(1);
}
}).detach();
} else {
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Unable to connect to Flight Simulator").ToLocalChecked()));
}
}
void Initialize(Local<Object> exports) {
NODE_SET_METHOD(exports, "initializeSimConnect", InitializeSimConnect);
}
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
</code>
#include <node.h>
#include <windows.h>
#include <SimConnect.h>
#include <iostream>
#include <thread>
using namespace v8;
HANDLE hSimConnect = NULL;
Persistent<Function> callback;
enum EVENT_ID {
EVENT_SIM_START
};
void onSimulatorStart();
void CALLBACK MyDispatchProcRD(SIMCONNECT_RECV* pData, DWORD cbData, void* pContext) {
if (pData->dwID == SIMCONNECT_RECV_ID_EVENT) {
SIMCONNECT_RECV_EVENT* evt = (SIMCONNECT_RECV_EVENT*)pData;
if (evt->uEventID == EVENT_SIM_START) {
onSimulatorStart();
}
}
}
void onSimulatorStart() {
Isolate* isolate = Isolate::GetCurrent();
HandleScope handleScope(isolate);
Local<Function> cb = Local<Function>::New(isolate, callback);
cb->Call(isolate->GetCurrentContext(), Null(isolate), 0, nullptr).ToLocalChecked();
}
void InitializeSimConnect(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
if (!args[0]->IsFunction()) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Callback must be a function").ToLocalChecked()));
return;
}
Local<Function> cb = Local<Function>::Cast(args[0]);
callback.Reset(isolate, cb);
if (SUCCEEDED(SimConnect_Open(&hSimConnect, "SimConnect Test", NULL, 0, 0, 0))) {
std::cout << "Connected to Flight Simulator!" << std::endl;
SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_SIM_START, "SimStart");
std::thread([]() {
while (true) {
SimConnect_CallDispatch(hSimConnect, MyDispatchProcRD, NULL);
Sleep(1);
}
}).detach();
} else {
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Unable to connect to Flight Simulator").ToLocalChecked()));
}
}
void Initialize(Local<Object> exports) {
NODE_SET_METHOD(exports, "initializeSimConnect", InitializeSimConnect);
}
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
binding.gyp
"NAPI_DISABLE_CPP_EXCEPTIONS"
"target_name" : "simconnect",
"sources" : [ "src/simconnect.cpp" ]
<code>{
"targets" : [
{
"include_dirs": [
"./include"
],
"libraries": [
"../lib/SimConnect.lib"
],
"defines": [
"NAPI_DISABLE_CPP_EXCEPTIONS"
],
"target_name" : "simconnect",
"sources" : [ "src/simconnect.cpp" ]
}
]
}
</code>
{
"targets" : [
{
"include_dirs": [
"./include"
],
"libraries": [
"../lib/SimConnect.lib"
],
"defines": [
"NAPI_DISABLE_CPP_EXCEPTIONS"
],
"target_name" : "simconnect",
"sources" : [ "src/simconnect.cpp" ]
}
]
}
after every modifications, I run those commands :
node-gyp clean
node-gyp configure
node-gyp build
after the build, there is no errors.
So when I start my program I get this error :
<code>> [email protected] start
> electron . --enable-logging
App threw an error during load
Error: The specified module could not be found.
\?C:UsersblutiDocumentsFlightCareerbuildReleasesimconnect.node
at process.func [as dlopen] (node:electron/js2c/node_init:2:2214)
at Module._extensions..node (node:internal/modules/cjs/loader:1489:18)
at Object.func [as .node] (node:electron/js2c/node_init:2:2214)
at Module.load (node:internal/modules/cjs/loader:1214:32)
at Module._load (node:internal/modules/cjs/loader:1030:12)
at c._load (node:electron/js2c/node_init:2:13672)
at Module.require (node:internal/modules/cjs/loader:1242:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (C:UsersblutiDocumentsFlightCareerportal.js:1:20)
at Module._compile (node:internal/modules/cjs/loader:1391:14)
<code>> [email protected] start
> electron . --enable-logging
App threw an error during load
Error: The specified module could not be found.
\?C:UsersblutiDocumentsFlightCareerbuildReleasesimconnect.node
at process.func [as dlopen] (node:electron/js2c/node_init:2:2214)
at Module._extensions..node (node:internal/modules/cjs/loader:1489:18)
at Object.func [as .node] (node:electron/js2c/node_init:2:2214)
at Module.load (node:internal/modules/cjs/loader:1214:32)
at Module._load (node:internal/modules/cjs/loader:1030:12)
at c._load (node:electron/js2c/node_init:2:13672)
at Module.require (node:internal/modules/cjs/loader:1242:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (C:UsersblutiDocumentsFlightCareerportal.js:1:20)
at Module._compile (node:internal/modules/cjs/loader:1391:14)
</code>
> [email protected] start
> electron . --enable-logging
App threw an error during load
Error: The specified module could not be found.
\?C:UsersblutiDocumentsFlightCareerbuildReleasesimconnect.node
at process.func [as dlopen] (node:electron/js2c/node_init:2:2214)
at Module._extensions..node (node:internal/modules/cjs/loader:1489:18)
at Object.func [as .node] (node:electron/js2c/node_init:2:2214)
at Module.load (node:internal/modules/cjs/loader:1214:32)
at Module._load (node:internal/modules/cjs/loader:1030:12)
at c._load (node:electron/js2c/node_init:2:13672)
at Module.require (node:internal/modules/cjs/loader:1242:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (C:UsersblutiDocumentsFlightCareerportal.js:1:20)
at Module._compile (node:internal/modules/cjs/loader:1391:14)
So, what I know is that the ‘portal.js’ can without any problem found the ‘simconnect.node’ file by the module ‘simconnect’ seems to doesn’t find another module. Thanks for reading this and for replying me if you have a solution !
Install Cmake, check my architecture, delete node modules folder and reimport dependencies, type full path of libraries and includes files