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:On 04/30/14 02:42, Shuai Meng wrote:
Thank you.
2014-04-30 1:13 GMT+08:00 Piotr Caban <piotr.caban@gmail.com>:
On 04/29/14 17:25, Shuai Meng wrote:
S_OK, because the function has succeeded.2014-04-29 22:25 GMT+08:00 Piotr Caban <piotr.caban@gmail.com<mailto:piotr.caban@gmail.com>>:
No, I mean that you should do something like this:
VARIANT v;
...
V_VT(&v) = VT_EMPTY;
hr = VariantChangeType(..., &v);
if(FAILED(hr))
return hr;
...
if(res)
*res = v;
else
VariantClear(&v);
what will be returned after *res = v; or VariantClear(&v); ?
Then I think this the same as return VariantChangeType directly. How about writing like this:
if(res){V_VT(res) = VT_EMPTY;return VariantChangeType(res, arg, 0, VT_BOOL);}return S_OK;
Because whether the change succeed or not, VariantChangeType will return a value indicating the situation.
call CBool("blah")
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).
Jacek