3

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?

4

3 に答える 3

2

基になる例外が既に処理されているため、少し注意が必要です。

メッセージボックスが表示されないようにすることは、不可能ではないにしても困難です。フォアグラウンド ウィンドウの変化をキャッチするウォッチャー スレッドのような非常にハックな処理を実行してから、マウス クリック メッセージをアプリケーションの基になるメッセージ キューに手動で送信して、メッセージ ボックスの [OK] ボタンをトリガーしようとすることができます

そこで、2 つの提案があります。これは DLL 検索順序に関する公式トピックです。これを使用して検索をエミュレートし、事前にファイルを見つけることができます。

それをしたくない場合は、LoadLibraryからメソッドをインポートしkernel32.dll、それを呼び出して、WintabDN ライブラリが使用しようとしている DLL をロードしてみてください。例外が発生した場合、WintabDN ライブラリも例外になることがわかります。LoadLibrary をバインドするのに役立つほぼ関連するトピックを次に示します。 .aspx

于 2012-09-05T13:01:09.937 に答える
1

次の答えを試してみてください。

(Wintab SDKの例は、システムにWintabがインストールされていないと実行されません。システムにタブレットがない(Wintabがない)場合、プログラムを機能させるにはどうすればよいですか?)

http://www.wacomeng.com/windows/docs/WacomWindevFAQ.html

于 2012-09-05T13:10:50.997 に答える
0

このメッセージボックスが表示されないようにするにはどうすればよいですか?

できません:

    public static bool IsWintabAvailable()
    {
        IntPtr buf = IntPtr.Zero;
        bool status = false;

        try
        {
            status = (CWintabFuncs.WTInfoA(0, 0, buf) > 0);
        }
        catch (Exception ex)
        {
            MessageBox.Show("FAILED IsWintabAvailable: " + ex.ToString());
        }

        return status;
    }

:D

私はライブラリ開発者が嫌いで、そのようなコードを書いています。どのエラー処理メカニズムを選択するかを決定するべきではありません。

ただし、オープンソースであるため、この問題を修正できます。
または、トラッカーにバグを投稿して、修正されるのを待つこともできます。

于 2012-09-05T13:01:54.907 に答える