I'm trying to use a third party COM object in a DLL when the DLL is being loaded (i.e. at DLL_PROCESS_ATTACH stage).
What's went wrong? Is there a solution? Or is it that, CoGetObject()
can not be used during DLL_PROCESS_ATTACH?
"JJ" wrote:
I'm trying to use a third party COM object in a DLL when the DLL is being
loaded (i.e. at DLL_PROCESS_ATTACH stage).
Seems like a bad idea. Have you read the warnings for DllMain? You
can't use anything tha calls LoadLibrary.
This extract from an old MSDN:
"Warning On attach, the body of your DLL entry-point function should
perform only simple initialization tasks,
[...]
Calling functions other than TLS, object-creation, and file functions
may result in problems that are difficult to diagnose. For example,
calling User, Shell, COM, RPC, and Windows Sockets functions (or any functions that call these functions) can cause access violation
errors, because their DLLs call LoadLibrary to load other system
components".
Note the mention of COM.
On Thu, 21 Apr 2022 00:00:12 +0100, Apd wrote:
Note the mention of COM.
Darn. I forgot about it. Thank you both for reminding me that.
Currently, I just use an initialization function which is conditionally called at start of all exported functions, to make sure that the COM
object is already exist before the functions do their main task.
Pity that, there's no mechanism for an auto-called DLL function after
the DLL has been loaded.
What you're doing is the same as an MSDN suggestion. They mention
using a named mutex to check if the init has been done.
On Fri, 22 Apr 2022 00:48:24 +0100, Apd wrote:
What you're doing is the same as an MSDN suggestion. They mention
using a named mutex to check if the init has been done.
How does a mutex take part in this mechanism? Cause in my case, the host process' thread which call LoadLibrary() to load my DLL, use the same
thread for calling the exported DLL function. If mutex is was created by
the DllMain(), it won't be signalled when the host process calls the
exported DLL function.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 379 |
Nodes: | 16 (2 / 14) |
Uptime: | 42:49:28 |
Calls: | 8,141 |
Calls today: | 4 |
Files: | 13,085 |
Messages: | 5,857,851 |