Re: How to use Invoke?
"Angus Comber" <nospam@gmail.com> wrote in message
news:eSZSI8FqGHA.516@TK2MSFTNGP05.phx.gbl
A COM function I need to call crashes. Although if I use in Visual
Basic it works for some reason. Can I instead to test try using
invoke?
The function which fails is like this:
hr = schema->Query(query, (IDispatch**)&resultset);
What type is resultset? If it's IDispatch* pointer, you don't need the
cast. If it is not, then you shouldn't use the cast - the function
expects IDispatch**, so you should give it IDispatch**. If you need some
other interface, call the function to get your IDispatch then use
QueryInterface to get whatever other interface you need.
But instead would my Invoke code be like below?
Although I get a valid pointer using code below but if I do anything
with it it crashes .
CComBSTR bstr = "'Field2' = \"07768385144\"";
// back reading
bstr.CopyTo(&dispparams.rgvarg[i].bstrVal);
dispparams.rgvarg[i].vt = VT_BSTR;
}
hr=schema->Invoke(0xa, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD,
&dispparams, (VARIANT*)&resultset, 0, 0);
You still don't show what type resultset is, and judging by it being
necessary for you to perform a cast, it is not VARIANT. The function
wants a VARIANT pointer, you must give it one.
delete [] dispparams.rgvarg;
Note that you are leaking memory here - you are not freeing the BSTR
allocated by CopyTo call above.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925