Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [platform-swt-dev] Implementing IID_IDispatch from within Eclipse


When you use COMObject to define your interface, all the parameters for the methods are ints.  Consequently you need to get your data out of the int.  For example, below is the QueryInterface method.  The riid is a pointer to a GUID and to get the GUID you must use COM.MoveMemory to extract the GUID object from the pointer.  Similarly, you need to use MoveMemory to fill in the address of the IDispatch object in ppvObject before returning.

private int QueryInterface(int riid, int ppvObject) {
       
        if (riid == 0 || ppvObject == 0)
                return COM.E_INVALIDARG;
        GUID guid = new GUID();
        COM.MoveMemory(guid, riid, GUID.sizeof);
       
        if (COM.IsEqualGUID(guid, COM.IIDIUnknown) || COM.IsEqualGUID(guid, COM.IIDIDispatch) {
                COM.MoveMemory(ppvObject, new int[] {iDispatch.getAddress()}, 4);
                AddRef();
                return COM.S_OK;
        }
       
        COM.MoveMemory(ppvObject, new int[] {0}, 4);
        return COM.E_NOINTERFACE;
}

Here is a snippet where the disparams are converted from a pointer to an array of Variant objects (args).

private int Invoke(int dispIdMember, int riid, int lcid, int dwFlags, int pDispParams, int pVarResult, int pExcepInfo, int pArgErr)
{
        ...
        // Construct an array of the parameters that are passed in
        // Note: parameters are passed in reverse order - here we will correct the order
        Variant[] args = null;
        if (pDispParams != 0) {        
                DISPPARAMS dispParams = new DISPPARAMS();
                COM.MoveMemory(dispParams, pDispParams, DISPPARAMS.sizeof);
                args = new Variant[dispParams.cArgs];
                int size = Variant.sizeof;
                int offset = (dispParams.cArgs - 1) * size;
               
                for (int j = 0; j < dispParams.cArgs; j++){
                        args [j] = new Variant();
                        args [j].setData(dispParams.rgvarg + offset);
                        offset = offset - size;
                }
        }
        ...
        return COM.S_OK;
}

There are other cases where you are passed a struct rather than a pointer to a struct.  In such a case, you need to treat each int in the struct as an incoming parameter.  For example, if you were passed a Variant, you would need to define the method something like:

private int VariantMethod(int variant_vt, int variant_reserved1, int variant_lVal, int variant_reserved2) {
}

You probably don't have this last case in IDispatch as everything seems to be a pointer to a struct or a pointer to a pointer to a VTable.



"Seymour Kellerman/Cambridge/IBM" <seymour_kellerman@xxxxxxxxxx>
Sent by: platform-swt-dev-admin@xxxxxxxxxxx

12/04/2002 08:38 AM
Please respond to platform-swt-dev

       
        To:        platform-swt-dev@xxxxxxxxxxx
        cc:        lmonson@xxxxxxxxxxxx
        Subject:        RE: [platform-swt-dev] Implementing IID_IDispatch from within Eclipse



I have a further question on the current SWT strategy for implementing an IDispatch interface.  Please bear with me; I'm not a COM expert, but I do know that I need to pass a IDispatch objects to an embedded IE WebBrowser so my external Java code can get called back.


The request for the addition to SWT is discussed here: http://dev.eclipse.org/mhonarc/lists/platform-swt-dev/msg00716.html


and a feature request is here:
http://dev.eclipse.org/bugs/show_bug.cgi?id=13503 (also in bug 8727).

So my question is: if I use Lynn Monson's recipe for creating an IDispatch, (using the org.eclipse.swt.internal.ole.win32.COMObject class), how do I "crack the parameters to the IDispatch methods"? Can you show an example of cracking a parameter?


Thanks in advance,


Seymour Kellerman
 
IBM Research

1 Rogers Street
Cambridge MA 02142
Seymour_Kellerman@xxxxxxxxxx

617 693-5412



Back to the top