• 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.

Trouble Loading a Simconnect DLL from dll.xml

Messages
65
Country
us-massachusetts
Hi folks,

I wonder if a couple of you wouldn't mind pondering my predicament for a couple minutes, I'd be exceedingly grateful:

Problem:
When my DLL loads, the sim freezes and never recovers. I get no errors in my simconnect log file. The last message is that the previous dll has loaded successfully.

By now, I have removed all of my real code and am just trying to get the thing to load. When I take away DLLStart or DLLStop, or remove them from the .def file, the sim loads just fine (the dll doesn't, of course), and I get the expected error messages in the simconnect log to the effect that the dll loader can't find DLLStart and DLLStop. But when I do export those functions, I get no error, just a complete freeze.

further notes:
- I've tried the three functions here with all manner of decorations and declspecs (EXTERN_C, WINAPI, declspec(dllExport) and what have you). The behavior is the same. I've tried them void, and as returning int. Same behavior.

- I'm reluctant to suspect that it has anything to do with simconnect itself, as: a) all my other addons load just fine, b) I'm not even attempting to open a client or call any simconnect functions at the moment, and c) I've been developing this project as a gauge loaded from panel.cfg for the past couple weeks and its simconnect client and all its functionality works fine. It's only last night when I tried to switch it to loading from dll.xml (which I'd really like to do) that I get issues.

so has anyone here encountered something similar and licked it?

Thanks so much for taking a look at this, FSDevelopers. Y'all are a bunch of seriously smart people and I'm forever indebted to you.

Sincerely,
Farley


CODE:

my main .cpp file, CarrierExtensions.cpp:

/////////////////////////////////////////////////////////////
#include "gauges.h"

PANELS *Panels;

//The actual DLL entry point. Stores the DLL base address
BOOL APIENTRY DllMain(HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
{
// hModule = hDLL;
return TRUE;
}

void DLLStart(void)
{
}

void DLLStop(void)
{
};
//////////////////////////////////////////////////////////////



my .def file:

LIBRARY "CarrierExtensions"
EXPORTS
DLLStart
DLLStop
 
Messages
1,243
Country
canada
Have you tried this style? I did a dll a long time ago and used MFC, but the SDK example is:

Code:
// Include files are no different than for an EXE

HANDLE hSimConnect = NULL;

void CALLBACK MyDispatchProcDLL(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext)
{
  // Callback code for a DLL is no different than for an EXE
}

//
// The DLLStart function must be present.
//
int __stdcall DLLStart(void)
{
  HRESULT hr;
  if (SUCCEEDED(SimConnect_Open(&hSimConnect, "DLL name", NULL, 0, NULL, 0)))
  {
    printf("\nConnected...");

    // Place all initialization code for the client in this function

    hr = SimConnect_CallDispatch(hSimConnect, MyDispatchProcDLL, NULL);
  }
  return 0;
}

//
// The DLLStop function must be present.
//
void __stdcall DLLStop(void)
{
  // Close the client
  if (hSimConnect != NULL)
    HRESULT hr = SimConnect_Close(hSimConnect);
}
 
Messages
65
Country
us-massachusetts
Hi Ron,

Thanks so much for your reply.

I tried it with these function signatures and _stdcall specification, and without the DLL main as well, and I get the exact same behavior.

At this point I doubt that the issue is related to what is inside the start/stop functions, as when my debugger is attached, no breakpoints are hit in any of the functions. Something is failing after the Sim reads my exported names, before it successfully calls DLLStart(), and frankly, I'm completely mystified as to what it could be...

Farley
 
Messages
65
Country
us-massachusetts
UPDATE: [SOLVED]

Ok, I figured it out:

It was the one thing that I should have expected to fail in between reading the exports and calling the entry function: static object initialization.

Even though I wasn't including any of my header files in the file I included here, the cpp files were still included in the project build. One of my classes has a static std::unique_ptr member, which I was initializing with "new object()". I don't remember what is in that constructor, it worked perfectly when I built it as a gauge. But apparently something in there causes an issue when it loads from dll.xml. I took away the static member, and the dll loads up. Now to add my actual code back in one bit at a time and make sure it all works. I feel pretty stupid for wasting so many hours stumped by this... :(

Thanks,
Farley
 
Top