Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-29-2008, 08:53 PM
Member
 
Join Date: Oct 2008
Posts: 3
nmarathe is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-30-2008, 08:08 PM
Member
 
Join Date: Oct 2008
Posts: 3
nmarathe is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-31-2008, 09:38 PM
Member
 
Join Date: Oct 2008
Posts: 3
nmarathe is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
plugin for using jsf in eclipse shu2hua Eclipse 0 05-30-2008 07:54 AM
IDL Plugin for Eclipse JavaForums Java Blogs 0 02-08-2008 03:40 PM
Eclipse Plugin Dev eva Eclipse 1 01-22-2008 12:56 AM
AnyEdit Plugin For Eclipse Plugin JavaForums Eclipse 0 05-18-2007 02:28 PM
plugin for eclipse sin Eclipse 1 05-10-2007 09:43 PM


All times are GMT +3. The time now is 01:27 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org