我想通过API获得一个正在运行中的进程的图标,通过下面的方法实现[DllImport("Shell32.dll")]
public static extern int ExtractIcon(IntPtr h, string strx, int ii);void GetIcon()
{
         filename = @"C:\WINDOWS\system32\cmd.exe";
         //filename = process.MainModule.FileName;          // 如果不注释掉就出错 ①
         Icon ic = myExtractIcon(filename, 0);
}protected virtual Icon myExtractIcon(string FileName,int iIndex)
{
try
{
IntPtr hIcon=(IntPtr)ExtractIcon(this.Handle,FileName,iIndex);
if(! hIcon.Equals(null))
{
Icon icon=Icon.FromHandle(hIcon);
return icon;
}
}
catch(Exception ex)
{ MessageBox.Show(ex.Message,"错误提示",0,MessageBoxIcon.Error);} 
return null;
}说明:
① 在 System.ArgumentException 中第一次偶然出现的“System.Drawing.dll”类型的异常 
传递给 Icon 的 Win32 句柄无效或者类型错误