2 messages in net.java.dev.jna.usersRe: [jna-users] What happens if a nat...
FromSent OnAttachments
Steve Sobol (JDN)Jan 21, 2009 9:48 pm 
Wayne MeissnerJan 21, 2009 10:33 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] What happens if a native library can't be loaded?Actions...
From:Wayne Meissner (wmei@gmail.com)
Date:Jan 21, 2009 10:33:35 pm
List:net.java.dev.jna.users

An UnsatisfiedLinkError should be thrown - not sure if that will convert to something else like an ExceptionInitializationError because its in an static member, but it might.

The best way would be to not have the INSTANCE variable there, and to abstract the accesses into a wrapper class - use the real functions if the library loads, else do nothing, or some form of fallback.

2009/1/22 Steve Sobol (JDN) <java@stevesobol.com>:

Specifically,

interface DWMLibrary extends Library { DWMLibrary INSTANCE = (DWMLibrary) Native.loadLibrary("dwmapi",DWMLibrary.class); NativeLong DwmEnableComposition(int Action); NativeLong DwmIsCompositionEnabled(IntByReference pfEnabled); }

These two functions enable or disable Vista's Desktop Window Manager's Window Composition, effectively turning the Aero visual theme on or off, and check whether Window Composition is enabled.

This works on Windows Vista, and should also work on Windows Server 2008. It will fail on any earlier Windows OS, as dwmapi.dll is missing from earlier versions of Windows. It will also (obviously) fail on non-Windows operating systems.

My question: If dwmapi.dll doesn't exist (or can't be loaded for some other reason), will DWMLibrary.INSTANCE return null? That would be very convenient.

Microsoft's new marketing slogan for Windows is "Life Without Walls." But if you have no walls, how can you have windows?