2014-04-29 22:25 GMT+08:00 Piotr Caban <piotr.caban@gmail.com>:
On 04/29/14 16:04, Shuai Meng wrote:

Thank you for commenting.

2014-04-29 21:30 GMT+08:00 Piotr Caban <piotr.caban@gmail.com
<mailto:piotr.caban@gmail.com>>:


    On 04/29/14 15:06, Shuai Meng wrote:

        +    if(!res)
        +        return S_OK;

    You can't return early if res is NULL. You still need to do the
    conversion and return error if it fails.

I  don't quite get it, do you mean I should do like this:
if(res)
{
....
}
return S_OK;
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); ? 

    It would be nice to add following tests (these are the tests Jacek
    was asking for):

    Call ok(CBool("True") = true, "CBool(""True"") = " & CBool("True"))
    Call ok(CBool("fAlSe") = false, "CBool(""fAlSe"") = " & CBool("fAlSe"))


  I do notice it, but they failed in testbot. Just as MSDN says, If
/expression/ can't be interpreted as a numeric value, a run-time error
occurs.
You must have done something else incorrectly. Here's a run that succeeded: https://testbot.winehq.org/JobDetails.pl?Key=6665. It shows that CBool("True") returns true.

yes, I made a mistake. The error occurs when I test an empty string as Jacek have asked:
477 Call ok(CBool("") = True, "CBool("""") = " & CBool(""))
478 Call ok(getVT(CBool("")) = "VT_BOOL", "getVT(CBool("""")) = " & getVT(CBool("")))
I have tried to solve it like this:
477 Call ok(CBool("") = True, "CBool("") = " & CBool(""))
478 Call ok(getVT(CBool("")) = "VT_BOOL", "getVT(CBool("")) = " & getVT(CBool(""))) 
and this:
477 Call ok(CBool("") = True, "CBool(" & "" & ") = " & CBool(""))
478 Call ok(getVT(CBool("")) = "VT_BOOL", "getVT(CBool(" & "" & ")) = " & getVT(CBool("")))
They all don't work...The problem is how describe an empty string between two quotation marks.

 


    sub testCBoolError
         on error resume next

         call Err.clear()
         call CBool("#FALSE#")
         call ok(Err.number = 458, "Err.number = " & Err.number)
    end sub
    Call testCBoolError

Is this function written to provoke an error on purpose in order to test
CBool("#FALSE#")?
It's meant to handle error returned by CBool("#FALSE#"). Other invalid parameters may be tested in the same way.

Cheers,
Piot
r