C#调用API遇到类似PrivateExtractIcons这种输出参数应该如何做?

hpygzhx520 2014-07-05 02:12:21
PrivateExtractIcons圆形如下:

UINT WINAPI PrivateExtractIcons(
_In_ LPCTSTR lpszFile,
_In_ int nIconIndex,
_In_ int cxIcon,
_In_ int cyIcon,
_Out_opt_ HICON *phicon,
_Out_opt_ UINT *piconid,
_In_ UINT nIcons,
_In_ UINT flags
);
我应该怎么定义呢?

[DllImport("User32.dll", EntryPoint = "PrivateExtractIconsA", CharSet = CharSet.Unicode)]
public static extern int PrivateExtractIcons(string lpszFile, int nIconIndex, int cxIcon, int cyIcon, ref IntPtr phicon, ref IntPtr piconid, int nIcons, int flags);
这样对吗?反复测试总是得不到正确的结果,哪位指点下应该怎么调用?

我主要是要学习这类参数应该怎么处理,所以替代方案部考虑。

比如获取url.dll中的第一个图标,谢谢。
...全文
331 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hpygzhx520 2014-07-05
  • 打赏
  • 举报
回复
自己疏忽,头昏了,参数传错了!picon, 1, LR_DEFAULTCOLOR 同样讲解下A\W的事情吧,我传的是string呢,貌似必须使用W的才会成功,为什么
hpygzhx520 2014-07-05
  • 打赏
  • 举报
回复
应该只关系到第一个参数吧,我直接传字符串,不应该用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); 一样不成功,请指点,谢谢!
gomoku 2014-07-05
  • 打赏
  • 举报
回复
PrivateExtractIconsA", CharSet = CharSet.Unicode 指定了Ansi的函数,传参却用Unicode,自己跟自己过不去。 把A换成W。

110,546

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧