PrivateExtractIconsA", CharSet = CharSet.Unicode
指定了Ansi的函数,传参却用Unicode,自己跟自己过不去。把A换成W。

解决方案 »

  1.   

    应该只关系到第一个参数吧,我直接传字符串,不应该用PrivateExtractIconsA吗?我换成这样:public const int LR_DEFAULTCOLOR = 0x0;
            [DllImport("User32.dll", EntryPoint = "PrivateExtractIconsW", CharSet = CharSet.Auto)]
            public static extern int PrivateExtractIcons(string sFile, int nIconIndex, int cxIcon, int cyIcon, ref IntPtr phicon, ref IntPtr piconid, int nIcons, int flags);        public static Image GetDLLIcon(string tFile, int nIconIndex, int iconSize)
            {
                Icon tmpImg=null;
                IntPtr tmp = IntPtr.Zero;
                IntPtr picon = IntPtr.Zero;
                PrivateExtractIcons(tFile, nIconIndex, iconSize, iconSize,ref tmp,ref picon, 0, LR_DEFAULTCOLOR);
                tmpImg=System.Drawing.Icon.FromHandle(tmp);
                return tmpImg.ToBitmap();
            }调用System.Drawing.Image img = Win32API.GetDLLIcon("url.dll", 0, 16);或者System.Drawing.Image img = Win32API.GetDLLIcon(@"C:\Windows\System32\url.dll", 0, 16);一样不成功,请指点,谢谢!
      

  2.   

    自己疏忽,头昏了,参数传错了!picon, 1, LR_DEFAULTCOLOR同样讲解下A\W的事情吧,我传的是string呢,貌似必须使用W的才会成功,为什么