我寫這是越來越使用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