我写这是越来越使用user32.dll
GetIconInfo
功能当前光标的图标信息的应用程序,它正常工作了一段时间,但一段时间后,它开始在ICONINFO.hbmMask
(一些负值提供错误信息),并在下一行我尝试从Bitmap.HBitmap(bitmask)
得到位图对象,它抛出一个异常:的GetIconInfo功能不能正常工作
A Generic error occured in GDI+.
从那里onwords,它不断地给这个例外,因为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
尝试发布一些代码。 – 2009-09-03 05:54:17
也许这篇文章有帮助:[调试GDI资源泄漏](https://blogs.msdn.microsoft.com/oldnewthing/20170519-00/?p=96195) – coz 2017-05-24 04:39:39