<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">On 29/05/2020 17:19, Mike Kaganski
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:AM0PR07MB40671F65E172D69CCB5C1DE0D68F0@AM0PR07MB4067.eurprd07.prod.outlook.com">
<pre class="moz-quote-pre" wrap="">On 29.05.2020 17:41, julien2412 wrote:
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">...
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
Ctor of ODriver should store the previous status if COM initialization,
if it wants to re-initialize it with a specific concurrency. It should
check the failure code to detect if it was rejected because of different
mode (RPC_E_CHANGED_MODE); and if so, it should call CoUninitialize as
many times as needed to succeed with CoInitializeEx; then it needs to
additionally call CoInitializeEx the same number of times (so that the
total number of initializations is increased by 1). Then in dtor, it
should reverse that: if it hadn't needed to change mode in ctor, then
just call CoUninitialize once; otherwise, call CoUninitialize as many
times as needed to CoInitializeEx with old mode to succeed, then call
CoInitializeEx as many times that total initialize count is decremented
by 1 compared to before entering dtor. That should account for possible
intermediate unpaired calls to CoInitialize(Ex)/CoUninitialize in the
same thread, and make sure that the calling code is in ~consistent state
... (however even this is a hack, and it would be better to find out why
does it need to change the mode at all - i.e., if we can make sure it
always used in appartment-threaded code).</pre>
</blockquote>
<p><tt>Thank you for your feedback Mike.<br>
</tt></p>
<p><tt>I submitted on gerrit
<a class="moz-txt-link-freetext" href="https://gerrit.libreoffice.org/c/core/+/95174">https://gerrit.libreoffice.org/c/core/+/95174</a>.</tt></p>
<p><tt>Just quote the comment I put in gerrit:</tt></p>
<p><tt>"</tt><tt><span id="output" class="style-scope
gr-linked-text">It seems we don't need to count the number of
times CoInitializeEx has been called.
From <a
href="https://docs.microsoft.com/en-us/windows/win32/learnwin32/error-handling-in-com"
target="_blank" rel="noopener" class="style-scope
gr-linked-text">https://docs.microsoft.com/en-us/windows/win32/learnwin32/error-handling-in-com</a>:
"The success code S_FALSE deserves mention. Some methods use
S_FALSE to mean, roughly, a negative condition that is not a
failure. It can also indicate a "no-op"—the method succeeded,
but had no effect. For example, the CoInitializeEx function
returns S_FALSE if you call it a second time from the same
thread"</span></tt></p>
<p><tt><span id="output" class="style-scope gr-linked-text">For the
rest, I tried to save initial state (if different from " </span></tt><tt><span
id="output" class="style-scope gr-linked-text">COINIT_APARTMENTTHREADED")
in ctr to reuse it in dtr.<br>
</span></tt></p>
<p><span id="output" class="style-scope gr-linked-text"><tt>Julien</tt><br>
</span></p>
<p><br>
</p>
</body>
</html>