Author |
Message |
Alberto Vel #1 / 4
|
 Invoke help
Hello, how to use Invoke for methods returning "complex" data types? Well, not exactly: let me explain. I'm trying to use IDispatch to instanciate a COM object (via CoCreateInstance), look for its methods/properties (with QueryInterface and GetIDsOfNames), and finally call Invoke to invoke a method and get the result back. I am now able to correctly place a call to Invoke for a COM object method that returns a BSTR value. For example, I can call this simple method from a VB com object, and read the resulting BSTR: --> Public Function Foo(byval szParam As String) As String Now, I want to do the same for a method returning an object (a MSXML2.IXMLDOMNodeList). The VB method looks like: --> Public Function Foo2(byval szParam as String) as IXMLDOMNodeList My call to Invoke looks like the following: I have a VARIANT in which I store the Invoke result, and if it receives a BSTR I can easily use pRsult.bstrVal to access the returned value. hresult = pdisp->Invoke(dispid,IID_NULL,LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD | DISPATCH_PROPERTYGET &callParams, &pResult, NULL, &nArgErr) ); Now, I imagine that VARIANT can hold my IXMLDOMNodelist: the problem is I don't know how to parse the returned value. That is, how can I get my pResult VARIANT and generate a IXMLDOMNodeListPtr containing its value? Ideally, I'd write: IXMLDOMNodeListPtr myNodelist; myNodelist = (IXMLDOMNodeListPtr)pResult; ... but of course this is wrong. Can somebody help? Finally, I also would like to understand how to extract the object's methods and properties list, and extract methods' parameters list and datatypes: URLs and sample code *greatly* appreciated ;). Thank you, AL.
|
Wed, 08 Sep 2004 00:54:57 GMT |
|
 |
Igor Tandetni #2 / 4
|
 Invoke help
The returned variant will contain an IUnknown or IDispatch pointer (VT_UNKNOWN or VT_DISPATCH variant type, correspondingly). You extract this pointer and QI it for whatever interface you expect to receive. -- With best wishes, Igor Tandetnik "For every complex problem, there is a solution that is simple, neat, and wrong." H.L. Mencken
Quote: > Hello, > how to use Invoke for methods returning "complex" data types? > Well, not exactly: let me explain. > I'm trying to use IDispatch to instanciate a COM object (via > CoCreateInstance), look for its methods/properties (with QueryInterface and > GetIDsOfNames), and finally call Invoke to invoke a method and get the > result back. > I am now able to correctly place a call to Invoke for a COM object method > that returns a BSTR value. > For example, I can call this simple method from a VB com object, and read > the resulting BSTR: > --> Public Function Foo(byval szParam As String) As String > Now, I want to do the same for a method returning an object (a > MSXML2.IXMLDOMNodeList). The VB method looks like: > --> Public Function Foo2(byval szParam as String) as IXMLDOMNodeList > My call to Invoke looks like the following: I have a VARIANT in which I > store the Invoke result, and if it receives a BSTR I can easily use > pRsult.bstrVal to access the returned value. > hresult = pdisp->Invoke(dispid,IID_NULL,LOCALE_SYSTEM_DEFAULT, > DISPATCH_METHOD | DISPATCH_PROPERTYGET > &callParams, > &pResult, > NULL, > &nArgErr) ); > Now, I imagine that VARIANT can hold my IXMLDOMNodelist: the problem is I > don't know how to parse the returned value. That is, how can I get my > pResult VARIANT and generate a IXMLDOMNodeListPtr containing its value? > Ideally, I'd write: > IXMLDOMNodeListPtr myNodelist; > myNodelist = (IXMLDOMNodeListPtr)pResult; > ... but of course this is wrong. Can somebody help? > Finally, I also would like to understand how to extract the object's methods > and properties list, and extract methods' parameters list and datatypes: > URLs and sample code *greatly* appreciated ;). > Thank you, > AL.
|
Wed, 08 Sep 2004 01:13:28 GMT |
|
 |
Alberto Vel #3 / 4
|
 Invoke help
Dear Igor,
Quote: > The returned variant will contain an IUnknown or IDispatch pointer > (VT_UNKNOWN or VT_DISPATCH variant type, correspondingly). You extract > this pointer and QI it for whatever interface you expect to receive.
I get a VT_DISPATCH pointer out of the Invoke function, but then I'm not able to successfully QI to go on with it. I tried this way: pResult is the VT_DISPATCH type variant I get back from calling Invoke(), and here's my code for QI: IXMLDOMNodeListPtr outList; switch(pResult.vt) { case VT_DISPATCH: try { _bstr_t szInterfaccia = L"MSXML2.IXMLDOMNodeList"; IID iid; HRESULT rc = IIDFromString(szInterfaccia, &iid); if(rc != S_OK) MessageBox(szInterfaccia + " : IID not found"); TESTHR( punk->QueryInterface(iid, (void**)&outList) ); } catch( _com_error err ) { //always fall here } [...] } I get errors on calling IIDFromString(); I even tried not to use this, giving directly IID_IXMLDOMNodeList as the first parameter for QI(), but only get errors. Can you help me telling where am I wrong? Thank you, AL. Quote:
>> Hello, >> how to use Invoke for methods returning "complex" data types? >> Well, not exactly: let me explain. >> I'm trying to use IDispatch to instanciate a COM object (via >> CoCreateInstance), look for its methods/properties (with >> QueryInterface and GetIDsOfNames), and finally call Invoke to invoke a >> method and get the result back. >> I am now able to correctly place a call to Invoke for a COM object >> method that returns a BSTR value. >> For example, I can call this simple method from a VB com object, and >> read the resulting BSTR: >> --> Public Function Foo(byval szParam As String) As String >> Now, I want to do the same for a method returning an object (a >> MSXML2.IXMLDOMNodeList). The VB method looks like: >> --> Public Function Foo2(byval szParam as String) as IXMLDOMNodeList >> My call to Invoke looks like the following: I have a VARIANT in which >> I store the Invoke result, and if it receives a BSTR I can easily use >> pRsult.bstrVal to access the returned value. >> hresult = pdisp->Invoke(dispid,IID_NULL,LOCALE_SYSTEM_DEFAULT, >> DISPATCH_METHOD | DISPATCH_PROPERTYGET &callParams, &pResult, >> NULL, >> &nArgErr) ); >> Now, I imagine that VARIANT can hold my IXMLDOMNodelist: the problem >> is I don't know how to parse the returned value. That is, how can I >> get my pResult VARIANT and generate a IXMLDOMNodeListPtr containing >> its value? >> Ideally, I'd write: >> IXMLDOMNodeListPtr myNodelist; >> myNodelist = (IXMLDOMNodeListPtr)pResult; >> ... but of course this is wrong. Can somebody help? >> Finally, I also would like to understand how to extract the object's >> methods and properties list, and extract methods' parameters list and >> datatypes: URLs and sample code *greatly* appreciated ;). >> Thank you, >> AL.
|
Tue, 14 Sep 2004 21:51:19 GMT |
|
 |
Igor Tandetni #4 / 4
|
 Invoke help
IIDFromString does not do what you apparently think it does. It accepts the string of the form "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}" (where each X is a hex digit) and converts it to a GUID. Interface names are not registered anywhere, there's no way to get from the interface name to its IID (well, there is with a TLB, but it's not clear why you would want to). Use IID constant from the appropriate header file. I don't see how punk gets initialized. You don't seem to use pResult.pdispVal in any way. You don't say exactly what errors you get. Sorry, I can't help you, and I doubt anybody can unless you provide more information. -- With best wishes, Igor Tandetnik "For every complex problem, there is a solution that is simple, neat, and wrong." H.L. Mencken
Quote: > Dear Igor,
> > The returned variant will contain an IUnknown or IDispatch pointer > > (VT_UNKNOWN or VT_DISPATCH variant type, correspondingly). You extract > > this pointer and QI it for whatever interface you expect to receive. > I get a VT_DISPATCH pointer out of the Invoke function, but then I'm not > able to successfully QI to go on with it. > I tried this way: pResult is the VT_DISPATCH type variant I get back from > calling Invoke(), and here's my code for QI: > IXMLDOMNodeListPtr outList; > switch(pResult.vt) > { > case VT_DISPATCH: > try > { > _bstr_t szInterfaccia = L"MSXML2.IXMLDOMNodeList"; > IID iid; > HRESULT rc = IIDFromString(szInterfaccia, &iid); > if(rc != S_OK) > MessageBox(szInterfaccia + " : IID not found"); > TESTHR( punk->QueryInterface(iid, (void**)&outList) ); > } > catch( _com_error err ) > { > //always fall here > } > [...] > } > I get errors on calling IIDFromString(); I even tried not to use this, > giving directly IID_IXMLDOMNodeList as the first parameter for QI(), but > only get errors. > Can you help me telling where am I wrong? > Thank you, > AL.
> >> Hello, > >> how to use Invoke for methods returning "complex" data types? > >> Well, not exactly: let me explain. > >> I'm trying to use IDispatch to instanciate a COM object (via > >> CoCreateInstance), look for its methods/properties (with > >> QueryInterface and GetIDsOfNames), and finally call Invoke to invoke a > >> method and get the result back. > >> I am now able to correctly place a call to Invoke for a COM object > >> method that returns a BSTR value. > >> For example, I can call this simple method from a VB com object, and > >> read the resulting BSTR: > >> --> Public Function Foo(byval szParam As String) As String > >> Now, I want to do the same for a method returning an object (a > >> MSXML2.IXMLDOMNodeList). The VB method looks like: > >> --> Public Function Foo2(byval szParam as String) as IXMLDOMNodeList > >> My call to Invoke looks like the following: I have a VARIANT in which > >> I store the Invoke result, and if it receives a BSTR I can easily use > >> pRsult.bstrVal to access the returned value. > >> hresult = pdisp->Invoke(dispid,IID_NULL,LOCALE_SYSTEM_DEFAULT, > >> DISPATCH_METHOD | DISPATCH_PROPERTYGET &callParams, &pResult, > >> NULL, > >> &nArgErr) ); > >> Now, I imagine that VARIANT can hold my IXMLDOMNodelist: the problem > >> is I don't know how to parse the returned value. That is, how can I > >> get my pResult VARIANT and generate a IXMLDOMNodeListPtr containing > >> its value? > >> Ideally, I'd write: > >> IXMLDOMNodeListPtr myNodelist; > >> myNodelist = (IXMLDOMNodeListPtr)pResult; > >> ... but of course this is wrong. Can somebody help? > >> Finally, I also would like to understand how to extract the object's > >> methods and properties list, and extract methods' parameters list and > >> datatypes: URLs and sample code *greatly* appreciated ;). > >> Thank you, > >> AL.
|
Tue, 14 Sep 2004 22:44:50 GMT |
|
|
|