I am trying to make an application that may rely on a Wacom tablet. It is not necessary for the program to work, but it is a nice addition. Although, it should also work on computers without the Wintab32.dll installed and I would like to make a check to see if the DLL is available.
This piece of code generates an error and I would like to catch the error before it is generated. I am using WintabDN to support .net Wacom applications.
if (WintabDN.CWintabInfo.IsWintabAvailable())
{
// Initialize Wintab
WintabLib.Initialize(true);
WintabLib.OnWintabPacketReceived += WintabLib_OnWintabPacketReceived;
}
FAILED IsWintabAvailable: System.DllNotFoundException: Unable to load DLL 'Wintab32.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at WintabDN.CWintabFuncs.WTInfoA(UInt32 wCategory_I, UInt32 nIndex_I, IntPtr IpOutput_O) at WintabDN.CWintabInfo.IsWintabAvailable()
The problem with this error is that it is a messagebox and not an exception thrown by the package. How can I prevent this messagebox from showing up?
It's a bit tricky, because the underlying exception is already being handled.
Trying to block the messagebox from showing is going to be difficult, if not impossible. You can do something really hacky like a watcher thread to catch the foreground window changing, then manually sending a mouse click message to the application's underlying message queue to try and trigger the OK button on the message box.
So I have two suggestions: this is the official topic on DLL search order; you can use it to emulate the search and find the file in advance.
If you don't want to do that you could import the LoadLibrary
method from kernel32.dll
and then call that to try and load the DLL that the WintabDN library is trying to use; if you get an exception then you know that the WintabDN library will also. Here's an almost related topic that'll help bind LoadLibrary: http://blogs.msdn.com/b/jonathanswift/archive/2006/10/03/dynamically-calling-an-unmanaged-dll-from-.net-_2800_c_23002900_.aspx
Try following which answers:
(The Wintab SDK examples won't run without Wintab installed on the system. How can I make my program work if there is no tablet (no Wintab) on the system?)
http://www.wacomeng.com/windows/docs/WacomWindevFAQ.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With