[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools] Re: Accessing Active X Control


When you get the null return value, have you tried calling OleAutomation.getLastError() to see what the error was?

What kind of error are you getting?
What kind of method are you trying to invoke (property get, property set, method with arguments, ...)?

The OleAutomation object creates a wrapper for the IDispatch object associated with the OleClientSite.  Sometimes this is not the correct
IDispatch interface for the methods you are trying to invoke.  For example, to get the WordBasic IDispatch interface for the Word OLEDocument, I had to do the following:

OleClientSite clientSite = new OleClientSite(frame, "Word.Document");

// Get generic IDispatch interface
OleAutomation dispInterface = new OleAutomation(clientSite);
       
// Get Application
int[] appId = dispInterface.getIDsOfNames(new String[]{"Application"});
if (appId == null) return null;
Variant pVarResult = dispInterface.getProperty(appId[0]);
if (pVarResult == null) return null;
OleAutomation application = pVarResult.getAutomation();

// Get Word Basic
int[] wbId = application.getIDsOfNames(new String[]{"WordBasic"});
if (wbId == null) return null;
Variant pVarResult2 = application.getProperty(wbId[0]);
if (pVarResult2 == null) return null;
OleAutomation wordBasic = new OleWordBasic( pVarResult2.getAutomation());
return wordBasic;