C++ Module DLL Freeze P3D

SDK supports Prepar3D’s philosophy of an open development architecture and encourages third parties to bring new innovations with improved add-ons and training content.
Locked
johndoe
Posts: 1
Joined: Sun Feb 04, 2018 5:59 pm

C++ Module DLL Freeze P3D

Post by johndoe »

Hi,

I'm trying to figure out how I can run my module .DLL to do some calculation without freezing the main P3D.exe process.

Here's a sample of what I tried (I'm using the Cabin Confort Sample of the SDK and trying to add a method that will attempt to connect to a Pipe. The method is pipeInit(). I'm currently simply trying to make P3D continue working while the pipeInit is waiting and retrying to connect to the Pipe Server (which is not running for now).

void FSAPI module_init(void)
{
if (NULL != Panels)
{
ImportTable.PANELSentry.fnptr = (PPANELS)Panels;
CABINPanelCallbackInit();
std::thread t1(pipeInit); // I try to load as a seperate thread since the method is trying to connect every 1500ms and would freeze P3D.
}
}


Here's the pipeInit()

void pipeInit()
{
//Pipe Init Data
char buf[100];

lpszPipename1 = TEXT("\\\\.\\pipe\\toMyOtherApp");
lpszPipename2 = TEXT("\\\\.\\pipe\\fromMyOtherApp");

DWORD cbWritten;
DWORD dwBytesToWrite = (DWORD)strlen(buf);

//Thread Init Data
DWORD threadId;
HANDLE hThread = NULL;

BOOL Write_St = TRUE;

Finished = FALSE;
isPipeConnected = FALSE;

printf("C++ DLL running in Sim\n");

while ((hPipeTo == NULL || hPipeTo == INVALID_HANDLE_VALUE) || (hPipeFrom == NULL || hPipeFrom == INVALID_HANDLE_VALUE))
{
hPipeTo = CreateFile(lpszPipename1, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
hPipeFrom = CreateFile(lpszPipename2, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);

if ((hPipeTo == NULL || hPipeTo == INVALID_HANDLE_VALUE) || (hPipeFrom == NULL || hPipeFrom == INVALID_HANDLE_VALUE))
{
printf("Could not open the pipe - (error %d)\n", GetLastError());
Sleep(1500);
}
else
{
isPipeConnected = TRUE;
}
}

// Do something here after pipe connected
}
Locked