5
2005
Getting very native with JNIWrapper…
After much delay, I finally bought a copy of JNIWrapper, which is one very cool piece of software. Basically, it’s a set of libraries that gives you access to the Win32 libraries without the need of writing your own C wrapper classes for JNI.
And it’s not just for Win32 either – COM is supported out of the box! Run their nifty swing app, select the COM library you want to use (from the list they prepopulate from your registry!), set where you want it dump the Java wrapper classes, and boom. Java COM Factory wrappers, interfaces, and concrete classes are all there, ready to go – including all those dodgy Win32 BStr classes you need when calling COM. You can even tell your COM factories to instantiate ApartmentThreaded, Multithreaded and all that other Win32 goodness that really only David Chappell understands anyway.
Best of all, the documentation and tutorial examples are first class. By the end of my first session, I had created Java stubs for the COM object I was into, and made a few calls to see all was working as planned. Any that’s with pretty vanilla Win32 skills on my end.
If you’re not into COM, and need to call straight Win32 stuff, types are provided for all the standard Window enums, and you can roll your own if you have to. The exception handling is awesome, Win32 faults get converted to Java exceptions, getLastError() works, and it’s all memory-safe to boot.
They even ship with a “WinPack” library that puts a Java wrapper round a ton of common Win32 things you’re likely to want to do (like the Registry, Filesystem Watches, Window operations like transparency, Tray icons and all that nativey stuff). But if what you want is not in there already, it’s pretty trivial to call *any* Win32 routine if you know the signature.
If Win32 is not your bag, it ships with versions for Linux/Mac too! I am loving the power, and at $US120 for a bundle of *both* Win32 and Unix libraries, it’s an absolute steal – and we don’t have to mix up any C code in our project! Great work, guys!
3 Comments + Add Comment
Leave a comment
Glen Smith
Archives
- April 2012
- March 2012
- January 2012
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- April 2011
- March 2011
- January 2011
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005
- April 2005
- March 2005
- February 2005
- January 2005
- December 2004
- November 2004
- October 2004
- September 2004
- August 2004
- July 2004
- June 2004
- May 2004
- March 2004
- February 2004
- January 2004
- December 2003
- November 2003
- October 2003
- September 2003

An article by Glen





I looked at JNI wrapper and strongly considered using it. It looks like the best of the various commercial alternatives. In the end, I found the shared stubs method in Sun’s JNI book easier to use. It’s really a great starting point for someone just getting started with JNI.
Since I’m a bit of a type-safety nut, I modified the shared stubs code to be completely package private. Instead, the package exposes a mechanism where users supply an interface and a library to supply the native functions. As long as the method signatures in your interface match the function signatures in the library everything is good. In short, you get type-safety all through the Java code.
The hard part for someone with little C experience like me, was rewriting the SPARC and x86 assembly language part of shared stubs in portable C. Now, the same C code supports SPARC, x86, and MIPS. Additional processors are hopefully just a recompile away.
Bug me if you’re interested an I’ll try to get permission to release it as open-source. If you need COM support, com4j may also be worth your while.
Does anybody know anything about the rumored fast-and-easy JNI Sun developed. Is it just a rumor?
I have tried to use Winpack, however there is a problem. Some of Winpack’s classes imports other packages which were not in Winpack itself…
Example:
Import com.jniwrapper.util.EnumItem
import com.jniwrapper.util.Logger
“util” is not included in Winpack.
Thank you!
You need to include jniwrap.jar in your classpath along with winpack.jar. Winpack relies on jniwrap to perform the actual Win32 calls.