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