• Post Reply Bookmark Topic Watch Topic
  • New Topic

calling windows API from Java?  RSS feed

 
Jessica White
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, my friends:

I am working on converting an old project written in Visual J++ to pure java. It has direct call to Windows SDK API, such as:
Kernel32.createProcess()
User32.RegisterWindowMessage()
User32.PostMessage()

I am wondering in pure Java, is it possible to achieve this? If so, how do I do that. Any pointer to information would be greatly appreciate.
(BTW, my java application would only run on Windows platform.)

Thanks.
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ugh. Sounds like a fun project. You can use JNI (Java Native Interface) if you are sure that you will always be running on Windows. On the other hand, you could figure out what those calls are actually doing and try to duplicate them in pure Java.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CreateProcess you can certainly emulate in pure Java using the Runtime.exec() methods. If RegisterWindowMessage() and PostMessage() are being used for interprocess communication, then you're out of luck -- JNI is your only route. I think there are several commercial products that provide access to the whole Win32 API for Java via JNI.

But it's actually possible that RegisterWindowMessage() and PostMessage() are just being used within the single application, and if that's the case, then they can be replaced with plain old AWT/Swing event handling.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob is a library that might help with this task, as might be JCom.
 
Jessica White
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your reply. User32.RegisterWindowMessage() and User32.PostMessage() are used for communication with another application written in Visual C++. I guess I would try JNI first, the library needed are kernel32.lib and user32.lib, which are shipped with Windows. If that does not work, I would investigate the commercial package.

Thank you again for your warm replies!
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And do you migrate that other application too?
Perhaps you might use java.rmi instead.
 
Jessica White
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just want to put a closure on this topic.
I ended up using Coroutine component from NevaObject in order to make call to Wind32 API to send message to the other application.
The other application is actually a DDE server written in C++. I did not have to rewrite the DDE server at all. I also investigated the option of rewriting DDE server in pure Java. I checked out the DDE server component from NevaObject. From their online forum, looks like it is a bit heavy weight, uses quite some resource. And our old C DDE server utilizes Windows message mechanism for DDE function, is quite light-weight.
So, now the whole application is still a combination of Java and C and a little third party component. And it works great.
Thanks for everybody's input!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!