Invoke help 
Author Message
 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  
 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  
 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  
 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  
 
 [ 4 post ] 

 Relevant Pages 

1. Help on invoking help from app.

2. Invoking a method of the class CComDispatchDriver(Invoke N)

3. Help with invoking stored proc using OLE DB consumer templates

4. How to invoke the Microsoft Windows help compiler within a application

5. How to invoke .chm ( help ) file

6. Invoking Excel through MFC - HELP

7. Help: invoke another app to run on another computer

8. Need Help in invoking MatLab generated dlls in C#

9. function never invoked by source code, but app invoked it and crash, why???????????

10. Platform Invoke Problem

11. PLATFORM INVOKE ISSUE ON C#

12. Problem marshalling complex structures (invoking Win32 APIs)

 

 
Powered by phpBB® Forum Software