Re: IDispatch* to COMPtr
"Mcnamara, Sean D" <[email protected]> Mon, 26 Jun 2006 07:55:21 -0400
| Newsgroups | gmane.comp.windows.devel.jawin |
|---|---|
| Message-ID | <57F935D6BB6B2543AF5D835DCE7CAF27023697B8@MD61EX100.ad.honeywell-tsi.com> |
Thomas There are many ways to obtain an IDispatch* from some native source. However, the specifics of it depend largely on your environment. You say your IDispatch* pointer is pointing to a HTMLDocument of an embedded Internet Explorer instance. Where is this object residing? Is it in an in-process DLL? An out-of-process automation server? An in-process ActiveX object? Either way, your C++ app will need to expose the COM interface (with a method returning IDispatch* in your application's type library) programmatically. Using Visual Studio .Net you can do this fairly easily and there are tutorials on how to write DLLs and automation servers that you can instantiate directly using VB or Jawin. Be careful of multithreading issues when you are sharing COM objects across process boundaries. When you create your IEXPLORE.EXE instance (your out-of-process, embedded IE instance) you need to specify in your C++ code that it should be multi-threaded, on BOTH JAVA AND C++. I hope you aren't accessing this interface more than once every 2 or 3 seconds (and hopefully less frequently than that!) or the synchronization done by COM, combined with JNI, is going to kill application performance. But anyway, here's how to do it: http://jawinproject.sourceforge.net/jawinarchitecture.html#comThreading That's for Jawin, and http://msdn.microsoft.com/library/default.asp?url=3D/library/en-us/com/ht= m l/ffb79c0f-aeda-4ea1-aea8-afb79109837f.asp That's for C++. Use Multithreaded Apartments from both Jawin and C++. While I'm at it, I'll tell you one more thing -- when Jawin is using MTA, I've found that even very meticulous Java code, that calls .close() on all COMPtrs, doesn't always reduce the reference count on your out-of-process EXE in a way that it terminates itself. But I had this problem with Office apps -- maybe IEXPLORE is more cooperative ;) Need any other help? What part of the code are you stuck on? The C++ code to expose your IDispatch*, or the Jawin code to call it? Sean -----Original Message----- From: Discussion of Java/Win32/COM integration with Jawin [mailto:[email protected]] On Behalf Of Thomas Max Sent: Monday, June 19, 2006 8:06 AM To: [email protected] Subject: [JAWIN] IDispatch* to COMPtr Is there a way to access an IDispatch* (of IHTMLDocument) through JAWIN in Java. Description : I wan't to pass a IDispatch* Pointer (which is pointing to a HTMLDocument of an embedded Internet Explorer instance in C++) to my Java App. I successfully created the interface classes for the IHTMLDocument with the JAWIN-typebrowser and compiled them. But i don't know how to wrap the IDispatch* on C++ side to an JAWIN ComPtr on Java Side. Could anyone help me please ?