GetIconInfo
の関数を使用して現在のカーソルのアイコン情報を取得するアプリケーションを作成しuser32.dll
ました。しばらくの間は正常に動作しますが、しばらくすると間違った情報ICONINFO.hbmMask
(負の値) を提供し始め、次の行でから Bitmap オブジェクトを取得Bitmap.HBitmap(bitmask)
すると、例外がスローされます。
A Generic error occured in GDI+.
そこから、GetIconInfo
常に負の値を返すため、この例外が継続的に発生します(このコードはすべてループで動作しています)。
誰でもこの問題が何であるか教えてもらえますか? 次の反復例外を回避する方法は?
ここにコードがあります
while (true)
{
//DLLimport User32.dll
PlatformInvokeUSER32.ICONINFO temp;
//Get the current cursor
IntPtr curInfo = GetCurrentCursor();
Cursor cur;
Icon ic;
if (curInfo != null && curInfo.ToInt32() != 0 && isOSelected)
{
cur = CheckForCusrors(curInfo);
try
{
//Dllimport User32.dll
//after some time the temp.hbmMask begin to get -ive vlaue from following function call
PlatformInvokeUSER32.GetIconInfo(curInfo, out temp);
if (temp.hbmMask != IntPtr.Zero)
{
//due to negative value of hbmMask the following function generates an exception
Bitmap bitmask = Bitmap.FromHbitmap(temp.hbmMask);
ic = Icon.FromHandle(curInfo);
Bitmap bmpCur = ic.ToBitmap();
}
}
catch (Exception ee)
{
//Exception message is
//A Generic error occured in GDI+
//and this loop begins to throw exception continuously
}
}
}// while ended