Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"It's not just a computer -- it's your ass." -- Cal Keegan


devel / comp.os.ms-windows.programmer.win32 / Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?

SubjectAuthor
* CoGetObject() can not be called during DLL_PROCESS_ATTACH?JJ
+* Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?Apd
|`* Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?JJ
| `* Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?Apd
|  `* Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?JJ
|   `- Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?Apd
`- Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?R.Wieser

1
CoGetObject() can not be called during DLL_PROCESS_ATTACH?

<13bb7c947dt84$.ghdapgaf0e4n$.dlg@40tude.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=390&group=comp.os.ms-windows.programmer.win32#390

  copy link   Newsgroups: comp.os.ms-windows.programmer.win32
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jj4public@gmail.com (JJ)
Newsgroups: comp.os.ms-windows.programmer.win32
Subject: CoGetObject() can not be called during DLL_PROCESS_ATTACH?
Date: Thu, 21 Apr 2022 02:50:00 +0700
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <13bb7c947dt84$.ghdapgaf0e4n$.dlg@40tude.net>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="9ed35d89b5a6b3884a16b93499adcabf";
logging-data="31370"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19c2ifpklmNSjHZomrzH59I1IhVimVOMnw="
User-Agent: 40tude_Dialog/2.0.15.84
Cancel-Lock: sha1:0MiXGdxjVYsHTLV/JapQc77LC4Q=
X-Bitcoin: 1LcqwCQBQmhcWfWsVEAeyLchkAY8ZfuMnS
X-Face: \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pa d{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
 by: JJ - Wed, 20 Apr 2022 19:50 UTC

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

The COM object is instantiated using CoGetObject() like below, but it hangs.
For the sake of reproducing the problem in any system, the WMI service
object is used as an example.

CoInitializeEx(NULL, COINIT_MULTITHREADED); //returns zero. already checked.
CoGetObject(L"winmgmts:", NULL, IID_IDispatch, &pObj); //it hangs
//code execution never reached here

The code works fine if it's executed from an exported DLL function and
called by the host process, after LoadLibrary() returns.

What's went wrong? Is there a solution? Or is it that, CoGetObject() can not
be used during DLL_PROCESS_ATTACH?

Note: WMI has `WbemScripting.SWbemLocator` alternative class name for use
with CoCreateInstance(). The third party COM object I'm actually using, does
not have any alternative class name which is usable with CoCreateInstance().
So, I can not use CoCreateInstance().

Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?

<t3q39t$lh1$1@apd.eternal-september.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=391&group=comp.os.ms-windows.programmer.win32#391

  copy link   Newsgroups: comp.os.ms-windows.programmer.win32
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!apd.eternal-september.org!.POSTED!not-for-mail
From: not@all.invalid (Apd)
Newsgroups: comp.os.ms-windows.programmer.win32
Subject: Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?
Date: Thu, 21 Apr 2022 00:00:12 +0100
Organization: ad hoc
Lines: 22
Message-ID: <t3q39t$lh1$1@apd.eternal-september.org>
References: <13bb7c947dt84$.ghdapgaf0e4n$.dlg@40tude.net>
Injection-Date: Wed, 20 Apr 2022 23:00:13 -0000 (UTC)
Injection-Info: apd.eternal-september.org; posting-host="9950c45f40d388069dfd5c438a9604c9";
logging-data="22049"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+48KQJVyKoxtkIeZPgnHHI"
Cancel-Lock: sha1:s1TKOhOX9IWnXlxsMpmK5xZaHJ4=
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-Priority: 3
X-MSMail-Priority: Normal
 by: Apd - Wed, 20 Apr 2022 23:00 UTC

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

Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?

<t3r147$1g0m$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=392&group=comp.os.ms-windows.programmer.win32#392

  copy link   Newsgroups: comp.os.ms-windows.programmer.win32
Path: i2pn2.org!i2pn.org!aioe.org!BHGTVyTGRwF2ntnqLVfpDg.user.46.165.242.75.POSTED!not-for-mail
From: address@not.available (R.Wieser)
Newsgroups: comp.os.ms-windows.programmer.win32
Subject: Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?
Date: Thu, 21 Apr 2022 09:28:49 +0200
Organization: Aioe.org NNTP Server
Lines: 18
Message-ID: <t3r147$1g0m$1@gioia.aioe.org>
References: <13bb7c947dt84$.ghdapgaf0e4n$.dlg@40tude.net>
Injection-Info: gioia.aioe.org; logging-data="49174"; posting-host="BHGTVyTGRwF2ntnqLVfpDg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-Notice: Filtered by postfilter v. 0.9.2
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-Priority: 3
X-RFC2646: Format=Flowed; Original
X-MSMail-Priority: Normal
 by: R.Wieser - Thu, 21 Apr 2022 07:28 UTC

JJ

> What's went wrong? Is there a solution? Or is it that, CoGetObject()
> can not be used during DLL_PROCESS_ATTACH?

Likely exactly that. To extend upon Apds response, I think the relevant
part to it is named here :

https://docs.microsoft.com/en-us/windows/win32/api/objbase/nf-objbase-coinitialize

"Because there is no way to control the order in which in-process servers
are loaded or unloaded, do not call CoInitialize, CoInitializeEx, or
CoUninitialize from the DllMain function."

Regards,
Rudy Wieser

Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?

<1c7vxe4tiap4t$.147nxywq6wnnu.dlg@40tude.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=393&group=comp.os.ms-windows.programmer.win32#393

  copy link   Newsgroups: comp.os.ms-windows.programmer.win32
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jj4public@gmail.com (JJ)
Newsgroups: comp.os.ms-windows.programmer.win32
Subject: Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?
Date: Fri, 22 Apr 2022 03:44:57 +0700
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <1c7vxe4tiap4t$.147nxywq6wnnu.dlg@40tude.net>
References: <13bb7c947dt84$.ghdapgaf0e4n$.dlg@40tude.net> <t3q39t$lh1$1@apd.eternal-september.org>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="be425c1fd9b23954cc571e19652bc6c9";
logging-data="4065"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+OjB20eYiIdEQeulU0VoorcoeOcTfaA28="
User-Agent: 40tude_Dialog/2.0.15.84
Cancel-Lock: sha1:D+Q11Y8V4XVEW080IfoWdam00m0=
X-Bitcoin: 1LcqwCQBQmhcWfWsVEAeyLchkAY8ZfuMnS
X-Face: \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pa d{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
 by: JJ - Thu, 21 Apr 2022 20:44 UTC

On Thu, 21 Apr 2022 00:00:12 +0100, Apd wrote:
> "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.

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.

Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?

<t3sqgd$dbk$1@apd.eternal-september.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=394&group=comp.os.ms-windows.programmer.win32#394

  copy link   Newsgroups: comp.os.ms-windows.programmer.win32
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!apd.eternal-september.org!.POSTED!not-for-mail
From: not@all.invalid (Apd)
Newsgroups: comp.os.ms-windows.programmer.win32
Subject: Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?
Date: Fri, 22 Apr 2022 00:48:24 +0100
Organization: ad hoc
Lines: 17
Message-ID: <t3sqgd$dbk$1@apd.eternal-september.org>
References: <13bb7c947dt84$.ghdapgaf0e4n$.dlg@40tude.net> <t3q39t$lh1$1@apd.eternal-september.org> <1c7vxe4tiap4t$.147nxywq6wnnu.dlg@40tude.net>
Injection-Date: Thu, 21 Apr 2022 23:48:29 -0000 (UTC)
Injection-Info: apd.eternal-september.org; posting-host="f1b095f1b3c1c06eda80e455e8a4b4e7";
logging-data="13684"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19FXd2mAVx+0G92ti7YkD3N"
Cancel-Lock: sha1:DTx5hgtvowMMxNw38EBsXwCnEtc=
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-Priority: 3
X-MSMail-Priority: Normal
 by: Apd - Thu, 21 Apr 2022 23:48 UTC

"JJ" wrote:
> 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.

Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?

<105if69fpmxwk.4cvzf8fovrg3$.dlg@40tude.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=395&group=comp.os.ms-windows.programmer.win32#395

  copy link   Newsgroups: comp.os.ms-windows.programmer.win32
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jj4public@gmail.com (JJ)
Newsgroups: comp.os.ms-windows.programmer.win32
Subject: Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?
Date: Fri, 22 Apr 2022 21:57:37 +0700
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <105if69fpmxwk.4cvzf8fovrg3$.dlg@40tude.net>
References: <13bb7c947dt84$.ghdapgaf0e4n$.dlg@40tude.net> <t3q39t$lh1$1@apd.eternal-september.org> <1c7vxe4tiap4t$.147nxywq6wnnu.dlg@40tude.net> <t3sqgd$dbk$1@apd.eternal-september.org>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="a71cbcb49e4c363abfbf02bd225d9dd2";
logging-data="983"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Wo7uGQeAX/+CRFFbs6jVPOexqYosiUQI="
User-Agent: 40tude_Dialog/2.0.15.84
Cancel-Lock: sha1:fTgSd+n2cXOime4MJN0AdCyeLUw=
X-Bitcoin: 1LcqwCQBQmhcWfWsVEAeyLchkAY8ZfuMnS
X-Face: \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pa d{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
 by: JJ - Fri, 22 Apr 2022 14:57 UTC

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.

Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?

<t3uirs$s7e$1@apd.eternal-september.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=396&group=comp.os.ms-windows.programmer.win32#396

  copy link   Newsgroups: comp.os.ms-windows.programmer.win32
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!apd.eternal-september.org!.POSTED!not-for-mail
From: not@all.invalid (Apd)
Newsgroups: comp.os.ms-windows.programmer.win32
Subject: Re: CoGetObject() can not be called during DLL_PROCESS_ATTACH?
Date: Fri, 22 Apr 2022 16:50:11 +0100
Organization: ad hoc
Lines: 21
Message-ID: <t3uirs$s7e$1@apd.eternal-september.org>
References: <13bb7c947dt84$.ghdapgaf0e4n$.dlg@40tude.net> <t3q39t$lh1$1@apd.eternal-september.org> <1c7vxe4tiap4t$.147nxywq6wnnu.dlg@40tude.net> <t3sqgd$dbk$1@apd.eternal-september.org> <105if69fpmxwk.4cvzf8fovrg3$.dlg@40tude.net>
Injection-Date: Fri, 22 Apr 2022 15:50:20 -0000 (UTC)
Injection-Info: apd.eternal-september.org; posting-host="f1b095f1b3c1c06eda80e455e8a4b4e7";
logging-data="28910"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19qf0vN8THYq5/pZ2bYH1LS"
Cancel-Lock: sha1:d5SQCzsqaUIjQKgKSLvbqHBPxPA=
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-Priority: 3
X-MSMail-Priority: Normal
 by: Apd - Fri, 22 Apr 2022 15:50 UTC

"JJ" wrote:
> 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.

This from MSDN:
"have the initialization routine create a named mutex, and have each
routine in the DLL call the initialization routine if the mutex does
not exist".

So it's only a matter of checking for the presence of one. You could
probably use some other system or process-wide object like an atom.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor