• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

C++ Module DLL Freeze P3D

Messages
9
Country
canada
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).

C++:
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()

C++:
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
}
 
Back
Top