This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

calling windows API from Java?

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 3061
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic