This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Equivalent of COM/OLE

 
Dave Brown
Ranch Hand
Posts: 301
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I havent got the foggiest idea how I would approach this, but how would I go about detecting if the computer my java program was running had MS Word installed, and then to take things further could I access it via its COM interface.

Actually I should reword the question, How can I acces any COM registered program ?

Thanks,

Dave.
 
Dmitry Melnik
Ranch Hand
Posts: 328
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about searching the registry?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose you would need to traverse the Registry, to find out what installed programs are on there. There's something called JNI Registry which I think can do it - Google for it. Alternatively a little bit of C programming and some JNI code would do it.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Google for "Java COM Bridge". There are a few open source and free implementations and a bunch of high-dollar commercial products. If you have C/C++ skills you could make your own custom native interfaces, too.

Since Java was designed for portability Sun didn't give us any hooks into COM or other Windows APIs. If you value COM interaction over portability, .NET might be a better choice than Java.
 
Dave Brown
Ranch Hand
Posts: 301
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My interest in COM really comes from wanting to operate with MS Word for document generation, and probably Outlook in the future for emailing/faxing.

Dave.
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done something like that. More specifically, our application is editing word documents stored on the server through Java. The only way I know of is by using a JNI layer. Your JNI layer will of course be in C++, and it can detect whether Word is installed on the system or not.

To get into more details, when you do CoCreateInstance in C++, that call will return an error code if Word is not installed on the system. You don't have to walk through the registry yourself. That call will go to the registry, find where Word is installed and invoke it. The same goes for all COM components that you might want to use.

However, COM is not a easy beast to tame, and I would'nt go into complexities if I didn't have prior experience with Windows and COM programming. Writing multi-threaded applications in COM is very complex, and you have to remember rules regarding which kind of COM objects you can use in which threads. You couple that with the fact that usually JNI layers don't handle threading, and threading is left to the calling Java application, and you will have problems if you leave COM objects lying around in memory. The rule of thumb for novices is don't use COM objects across threads, or if you really want to be safe:- always declare COM pointers as local variables;ie; instantiate at the start of your function, and release when you leave the function. That's not too efficient because every time you instantiate a COM object, the API has to walk through the registry and possibly load apps or libraries. Plus it is so hard to debug, because I don't know any way you can step into a COM function while debugging a Java app. WHen I was doing serious Java to COM programming, I would have both JBuilder and Visual Studio up, and I would make Visual Studio connect to JBuilder. It was a mess. I don't want to get into too many details of COM in a Java related board, so, in a nutshell, either be careful or try to gain expertise in COM

That Java COM bridge sounds interesting though. It might reduce your learning curve, but I am skeptical whether any Java COM bridge can solve the threading issues inherent in COM

Needless to say, your application will not be platform-independent, but I am sure you must have thought about that. I had heard about an open-source project regarding a pure Java implementation of a a word file reader. I think it was Jakarta POI http://jakarta.apache.org/poi/hwpf/projectplan.html But, when I was looking into it, it was'nt too mature. You might want to investigate that
[ March 24, 2005: Message edited by: Jayesh Lalwani ]
 
Dave Brown
Ranch Hand
Posts: 301
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Some very good info there. It certainly sounds like its no walk in the park to do what I was considering, in these respects .NET would certainly make things much easier, but then take away my platform independance. I wonder if there are any java packages that allow me to easily work with Open Office. Or something similar.
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dave Brown:
Thanks, Some very good info there. It certainly sounds like its no walk in the park to do what I was considering, in these respects .NET would certainly make things much easier, but then take away my platform independance. I wonder if there are any java packages that allow me to easily work with Open Office. Or something similar.


Doing this completely in Java will take away platform independence as well. COM is specific to Windows programs. I'm not aware of this technology being used on any other platforms, although that doesn't mean it isn't.

As for Open Office, I originally thought you would encounter similar problems. However, after visiting their website, it looks like there is some really good Java support. In particular, you may want to look at the Java UNO reference. This looks like Java classes that may be available for you to use. I don't know for sure if you have to download anything extra that doesn't come with the regular OpenOffice installation, but I wouldn't be surprised if you do. If you are interested in pursuing this further, you should poke around their website.

Layne
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic