调用api函数失败,怎么办?

ddqqll 2004-12-29 10:58:42
下面是代码,怎么返回值就是零呢?
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
struct GLYPHSET
{
public int cbThis;
public int flAccel;
public int cGlyphsSupported;
public int cRanges;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=4)]
public byte[] wcRange ;
}

[DllImport("Gdi32")]
static extern int GetFontUnicodeRanges(
IntPtr hdc,
ref GLYPHSET lpgs);

void getFontRange(ref int rs, ref int re)
{
GLYPHSET ggg = new GLYPHSET();

ggg.cbThis = Marshal.SizeOf(typeof(GLYPHSET));
int k = GetFontUnicodeRanges(Handle,ref ggg);

rs = ggg.wcRange[0] << 8 + ggg.wcRange[1];
re = ggg.wcRange[2] << 8 + ggg.wcRange[3];
}
...全文
189 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ddqqll 2004-12-29
  • 打赏
  • 举报
回复
另外又出问题了,public byte[] wcRange 数组中的长度应为16。取出来的值不理解。如下:
32 0 96 0 172 32 1 0 245 248 1 0 255 255 1 0。各位再帮一下忙
kakau 2004-12-29
  • 打赏
  • 举报
回复
呵呵
ddqqll 2004-12-29
  • 打赏
  • 举报
回复
我传错参数了,handle应该为graphics的句柄。
fanruinet 2004-12-29
  • 打赏
  • 举报
回复
把第二个参数改为null看看返回的什么(应该返回字节数)
GetFontUnicodeRanges(Handle, null);
liulxmooo 2004-12-29
  • 打赏
  • 举报
回复
up
ddqqll 2004-12-29
  • 打赏
  • 举报
回复
函数执行没错,返回值是0。也就是这个函数调用不成功
brbrm 2004-12-29
  • 打赏
  • 举报
回复
try-catch一下,有什么提示?
ddqqll 2004-12-29
  • 打赏
  • 举报
回复
结帐

110,571

社区成员

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

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

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