Results 1 to 5 of 5
  1. #1
    nmarathe is offline Member
    Join Date
    Oct 2008
    Posts
    3
    Rep Power
    0

    Default Help with Eclipse SWT - OLE plugin

    Hello Everybody,

    I am trying to embed an word document using the eclipse plugin org.eclipse.swt.win32.win32.x86_3.3.0.v3346. I want to catch the events such as DocumentChange which are defined in the interface IApplicationEvents4 in the MS Word.

    I have written the following code to do the same


    private void openDocument(String doc)
    {
    if (site != null && !site.isDisposed())
    site.dispose();
    file = new File(doc);

    site = new OleClientSite(frame, SWT.EMBEDDED,file);
    site.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);


    IUnknown objIUnknown = getDispPtr(site);

    if (objIUnknown != null)
    {
    GUID IIDIAppEvents = IIDFromString("{00020A01-0000-0000-C000-000000000046}");
    //GUID IAppEvents = IIDFromString("{000209FE-0000-0000-C000-000000000046}");
    //GUID IIDIAppEvents = IIDFromString("{00020A00-0000-0000-C000-000000000046}");

    int[] ppvObject = new int[1];
    if (objIUnknown.QueryInterface(COM.IIDIConnectionPoin tContainer, ppvObject) == COM.S_OK) {
    IConnectionPointContainer cpc = new IConnectionPointContainer(ppvObject[0]);
    int[] ppCP = new int[1];
    if (cpc.FindConnectionPoint(IIDIAppEvents, ppCP) == COM.S_OK) {
    IConnectionPoint cp = new IConnectionPoint(ppCP[0]);
    /*int[] pCookie = new int[1];
    if (cp.Advise(iDispatch.getAddress(), pCookie) == COM.S_OK)
    eventCookie = pCookie[0];*/
    cp.Release();
    }
    cpc.Release();
    }

    }
    }

    private GUID IIDFromString(String lpsz)
    {
    int length = lpsz.length();
    char[] buffer = new char[length + 1];
    lpsz.getChars(0, length, buffer, 0);
    GUID lpiid = new GUID();
    if (COM.IIDFromString(buffer, lpiid) == COM.S_OK) return lpiid;
    return null;
    }

    /**
    * @param args
    */
    public static void main(String[] args) {

    OleTest te = new OleTest();
    te.startShell();
    }

    private IUnknown getDispPtr(OleClientSite site)
    {
    Variant var = null;
    try
    {
    OleAutomation automation = new OleAutomation(site);
    var = new Variant(automation);
    return var.getUnknown();
    }
    catch (Exception e)
    {
    return null;
    }
    }

    The call if (cpc.FindConnectionPoint(IIDIAppEvents, ppCP) == COM.S_OK) {
    fails for some reason which i don't know. I have checked the IID for the IApplicationEvents4 and its correct. Please help. Please suggest what am I doing wrong here.

    Regards.

  2. #2
    nmarathe is offline Member
    Join Date
    Oct 2008
    Posts
    3
    Rep Power
    0

    Unhappy

    Hello All,

    I found out why the ConnectionPointContainer was failing here as i was calling it on the Word document instead of Application. Once i made those changes it started working. But now, i am not able to attach the sink object with the Connection point. I believe the following code is the culprit

    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, the method is returning COM_EN_NOINTERFACE, i don't know why :(....any ideas??

    thanks,

    Niranjan

  3. #3
    nmarathe is offline Member
    Join Date
    Oct 2008
    Posts
    3
    Rep Power
    0

    Default

    I have figured out the issues with the code and it is working fine. I wanted to pass a Java object to an external COM API, which expects an IDispatch pointer. I have written following code to implement the IDispatch method looking at some of the samples eclipse has provided

    // EventDispatch implements a simple IDispatch interface which will be called
    // when the event is fired.
    public class EventDispatch {
    private COMObject iDispatch;

    private int refCount = 0;
    private int eventID;
    //private GUID riid;
    final public static int DocumentChange = 0x00000003;

    public EventDispatch(int eventID) {
    this.eventID = eventID;
    //this.riid = riid;
    createCOMInterfaces();
    }

    public int getAddress() {
    return iDispatch.getAddress();
    }

    private void createCOMInterfaces() {
    iDispatch = new COMObject(new int[]{2, 0, 0, 1, 3, 4, 8}){
    public int method0(int[] args) {return QueryInterface(args[0], args[1]);}
    public int method1(int[] args) {return AddRef();}
    public int method2(int[] args) {return Release();}
    // method3 GetTypeInfoCount - not implemented
    // method4 GetTypeInfo - not implemented
    // method5 GetIDsOfNames - not implemented
    public int method6(int[] args) {return Invoke(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);}
    };
    }

    private void disposeCOMInterfaces() {
    if (iDispatch != null)
    iDispatch.dispose();
    iDispatch = null;
    }

    private int AddRef() {
    refCount++;
    return refCount;
    }

    private void OnDocumentChange()
    {
    System.out.println("From On document change");
    }
    private int Invoke(int dispIdMember, int riid, int lcid, int dwFlags,
    int pDispParams, int pVarResult, int pExcepInfo, int pArgErr) {
    switch (eventID) {
    case DocumentChange:
    System.out.println("Calling document change");
    OnDocumentChange();
    break;
    }
    return COM.S_OK;
    }

    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;
    }

    int Release() {
    refCount--;
    if (refCount == 0) {
    disposeCOMInterfaces();
    }
    return refCount;
    }

    However, when the external COM API calls the QueryInterface() on this object, the QueryInterface() implementation returns COM.E_NOINTERFACE as the pointer being passed doesn't match the IIDIUnknown or IIDIDispatch.

    It will be great if someone can point why this is happening or what am i doing wrong here ?? The external API I am using is the IConnectionPoint->Advise to register this object to recieve the DocumentChange event from Word Application.

    Thanks

    Niranjan

  4. #4
    condorian is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default can you share your findings?

    Hello,

    I'm facing a similar problem, with "as the pointer being passed doesn't match the IIDIUnknown or IIDIDispatch." I'm guessing it has to do with the signature of the interface of COMObject of the EventDispatch.

    If you have worked out the problem, could you please share your findings?

    thanks
    c

  5. #5
    condorian is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default

    It seems just by removing that check the event is fired and everything is ok...

    hmmm...

Similar Threads

  1. plugin for using jsf in eclipse
    By shu2hua in forum Eclipse
    Replies: 0
    Last Post: 05-30-2008, 05:54 AM
  2. Eclipse Plugin Dev
    By eva in forum Eclipse
    Replies: 1
    Last Post: 01-21-2008, 10:56 PM
  3. AnyEdit Plugin For Eclipse Plugin
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 05-18-2007, 12:28 PM
  4. plugin for eclipse
    By sin in forum Eclipse
    Replies: 1
    Last Post: 05-10-2007, 07:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •