0

I am using this example:

https://learn.microsoft.com/en-us/windows/win32/wmisdk/example--getting-wmi-data-from-the-local-computer

To get WMI Queries working. It works fine as part of a console app but when I move the code into a function and call it from DLLMain the ConnectServer function never returns.

I have tried running the function in another thread.

Seems this is an issue that others have run into: IWbemLocator ConnectServer call never returned

Are there any gotchas with using COM Server from DLLs?

  • 2
    You should not call WMI in DllMain, DllMain is a very special function https://devblogs.microsoft.com/oldnewthing/20040127-00/?p=40873 – Simon Mourier Nov 24 '21 at 12:28
  • Hi Simon. I do not call WMI from DLLMain. I call a function upon PROCESS_ATTACH which then handles the WMI processing. – jongjena Nov 24 '21 at 12:29
  • 1
    "when I move the code into a function and call it from DLLMain the ConnectServer function never returns"... you call it from DllMain, directly or indirectly, that doesn't matter – Simon Mourier Nov 24 '21 at 12:33
  • Ah I see, how can I use the WMI functionality from a DLL? Also, do you happen to know the reason that we cannot simply call from DllMain? – jongjena Nov 24 '21 at 12:36
  • Read the links. – Simon Mourier Nov 24 '21 at 12:41
  • @jongjena [Dynamic-Link Library Best Practices](https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-best-practices) – Remy Lebeau Nov 24 '21 at 19:42

0 Answers0