<div dir="ltr">Thank you, I got it. And I'll correct it.</div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-04-30 16:05 GMT+08:00 Jacek Caban <span dir="ltr"><<a href="mailto:jacek@codeweavers.com" target="_blank">jacek@codeweavers.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000"><div><div class="h5">
    <div>On 04/30/14 02:42, Shuai Meng wrote:<br>
    </div>
    <blockquote 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 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>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>
                  2014-04-29 22:25 GMT+08:00 Piotr Caban <<a href="mailto:piotr.caban@gmail.com" target="_blank">piotr.caban@gmail.com</a><br>
                </div>
                <mailto:<a href="mailto:piotr.caban@gmail.com" target="_blank">piotr.caban@gmail.com</a>>>:
                <div><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><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></div></div>
    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).<span class="HOEnZb"><font color="#888888"><br>
    <br>
    Jacek<br>
  </font></span></div>

</blockquote></div><br></div>