<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 04/30/14 02:42, Shuai Meng wrote:<br>
</div>
<blockquote
cite="mid:CAOhhAYPaepUquE1ZwYhyFg2cUHv35+goaAgcQ49qEbRWyVzyTA@mail.gmail.com"
type="cite">
<div dir="ltr">Thank you.<br>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">2014-04-30 1:13 GMT+08:00 Piotr Caban
<span dir="ltr"><<a moz-do-not-send="true"
href="mailto:piotr.caban@gmail.com" target="_blank">piotr.caban@gmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="">On 04/29/14 17:25, Shuai Meng wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="">
2014-04-29 22:25 GMT+08:00 Piotr Caban <<a
moz-do-not-send="true"
href="mailto:piotr.caban@gmail.com" target="_blank">piotr.caban@gmail.com</a><br>
</div>
<mailto:<a moz-do-not-send="true"
href="mailto:piotr.caban@gmail.com" target="_blank">piotr.caban@gmail.com</a>>>:
<div class=""><br>
No, I mean that you should do something like this:<br>
VARIANT v;<br>
...<br>
V_VT(&v) = VT_EMPTY;<br>
hr = VariantChangeType(..., &v);<br>
if(FAILED(hr))<br>
return hr;<br>
...<br>
<br>
if(res)<br>
*res = v;<br>
else<br>
VariantClear(&v);<br>
<br>
what will be returned after *res = v; or
VariantClear(&v); ?<br>
</div>
</blockquote>
S_OK, because the function has succeeded.
<div class=""><br>
</div>
</blockquote>
<div> </div>
<div>Then I think this the same as return VariantChangeType
directly. How about writing like this:</div>
<div><br>
</div>
<div>if(res)</div>
<div>{</div>
<div> V_VT(res) = VT_EMPTY;</div>
<div> return VariantChangeType(res, arg, 0, VT_BOOL);</div>
<div>}</div>
<div>return S_OK;</div>
<div><br>
</div>
<div>Because whether the change succeed or not,
VariantChangeType will return a value indicating the
situation.</div>
</div>
</div>
</div>
</blockquote>
<br>
Even if res is NULL (meaning that the return value is not used by
the script), the semantic of the code needs to be the same as if it
was used. It's just an optimization and optimizations can't change
semantics. For example:<br>
<br>
call CBool("blah")<br>
<br>
needs to return an error and you need to perform the conversion to
recognize the error. An other example why this is wrong is if you
try to convert an object. In such case, default value getter needs
to be called (and it's called by VariantChangeType in this case).<br>
<br>
Jacek<br>
</body>
</html>