Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] 100% CPU usage with excel automation - copied from newsgroup

Hi

 


I am trying to use swt automation to open an existing excel file. I picked up code from Snippet199.java to get it going http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet199.java?rev=HEAD&content-type=text/vnd.viewcvs-markup

The code works, as in it opens up the excel file for me. However my CPU usage goes up to 100% when excel is launched!

 

I tried to debug a little further and found that the following line of code in org.eclipse.swt.ole.win32.OleClientSite causes the CPU usage to go to 100%
/********************************************************/
protected void addObjectReferences() {
...
...
// Notify the control object that it is embedded in an OLE container
  COM.OleSetContainedObject(objIUnknown.getAddress(), true);
...
...
}
/********************************************************/


I commented out the call to OleSetContainedObject and recompiled swt.jar. The application seems to run fine now. But probably I have added a few memory leaks now.

The msdn documentation for OleSetContainedObject says that the implementation changed for OLE 2.01 http://msdn.microsoft.com/library/default.asp?url="">

I am not sure if this is a bug or something wrong with my implementation. Please find the relevant code below.

Environment details: Win XP / Office 2003 / Eclipse3.2M4 / jdk1.4.2_08

Any help would be greatly appreciated folks.

TIA
Aditya

 

/********************************************************/

 public static void main (String [] args) {
    Display display = new Display ();
    Shell shell = new Shell (display);
    shell.setLayout(new FillLayout());
    OleControlSite controlSite;
     OleAutomation application;
    OleAutomation workbook ;

    try {
        OleFrame frame = new OleFrame(shell, SWT.NONE);
        controlSite = new OleControlSite(frame, SWT.None, "Excel.Application");

    } catch (SWTError e) {
        System.out.println("Unable to open activeX control");
        return;
    }
    application = new OleAutomation(controlSite);
    int[] dispIDs = application.getIDsOfNames(new String[] {"Workbooks"});
    Variant pVarResult = application.getProperty(dispIDs[0]);
    OleAutomation workbooks = pVarResult.getAutomation();
    pVarResult.dispose();

     final int[] dispMIDs = workbooks.getIDsOfNames(new String[] {"Open"});

     Variant[] arguments = new Variant[]{new Variant("C:\\excel test\\Book1.xls")};
     if ((dispMIDs != null) && (dispMIDs.length > 0)) {
         workbook= workbooks.invoke(dispMIDs[0],arguments).getAutomation();
     }

     workbooks.dispose();

     dispIDs = application.getIDsOfNames(new String[] {"Visible"});
     pVarResult = application.getProperty(dispIDs[0]);
     application.setProperty(dispIDs[0], new Variant(true));
     pVarResult.dispose();


    while (!shell.isDisposed ()) {
        if (!display.readAndDispatch ()) display.sleep ();
    }
    application.dispose();
    display.dispose ();
}

 

/********************************************************/

 

 

PS: I had posted this problem initially at eclipse.platform.swt. The original is here- http://www.eclipse.org/newsportal/article.php?id=26779&group=eclipse.platform.swt#26779

 



____________________________________________________________________
IMPORTANT NOTICES:
This message is intended only for the addressee. Please notify
the sender by e-mail if you are not the intended recipient. If you
are not the intended recipient, you may not copy, disclose, or
distribute this message or its contents to any other person and any
such actions may be unlawful.

Banc of America Securities LLC("BAS") does not accept time
sensitive, action-oriented messages or transaction orders, including
orders to purchase or sell securities, via e-mail.

BAS reserves the right to monitor and review the content of all
messages sent to or from this e-mail address. Messages sent to or
from this e-mail address may be stored on the BAS e-mail system.
____________________________________________________________________

Back to the top