0

I have been working on a bit of software which interfaces with an SDK which communicates with a COM object (an external device). This SDK requires an MFC dialog and requires a window handle to work.

This is where it gets dicey. I have it working perfectly in MFC as an exe, and it connects to the COM object OK. However, when I compile it as a DLL and load the DLL from another console project, the SDK stalls on a function (my guess is that there's an issue with the COM object). Note that the MFC dialog and interface still works OK.

I don't have access to the code of the SDK, but from a conceptual point of view, what is different about loading a DLL with an MFC app versus running an exe that would cause this issue?

As far as I know, there shouldn't be any huge difference between the two. I've also enabled MFC in the console app that calls the dll

5
  • If you have a window around and/or COM objects that are STA-bound (ie: created on an STA thread) or both (STA communications works through window messages, UI works through window messages too), then you must pump windows messages per each STA thread. The symptom if you don't is typically something that hangs/stalls. Difficult to say more w/o more details. stackoverflow.com/questions/2222365/what-is-a-message-pump Commented Aug 2, 2024 at 16:19
  • @SimonMourier Thank you very much! The setup is using the regular MFC app, but in the InitDialog function, after initializing anything for the dialog, it calls a function to make a connection to the device. This is all triggered upon loading of the DLL. How can I make sure that the messages pump through Commented Aug 2, 2024 at 19:05
  • @SimonMourier Also, all calls to the SDK to the COM are in the same function, and I'm doing nothing different with the threading within the app. Any way to get it to behave the same way as if I ran it from an exe? Commented Aug 2, 2024 at 19:15
  • Difficult to say w/o some reproducing project. You basicall need to call the while (GetMessage(&msg, NULL, 0, 0)){TranslateMessage(&msg);DispatchMessage(&msg);} loop in the thread that creates the window and do you work on one (custom) message receptipon or in another thread somehow Commented Aug 2, 2024 at 21:39
  • This is a copy of an old MSDN KB article that was my go-to for issues like these 2 decades ago: betaarchive.com/wiki/index.php?title=Microsoft_KB_Archive/… Commented Aug 6, 2024 at 22:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.