如何在Pinvoke GlobalGetAtomName

时间:2017-02-23 19:48:26

标签: c# winapi

我想尝试使用Pinvoke从WindowsFomrs.Message获取字符串。

但是GlobalGetAtomName需要一个ushort,我有一个Intatr的LParam。

我该如何转换它?

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern uint GlobalGetAtomName(ushort nAtom, StringBuilder lpBuffer, int nSize);

protected override void WndProc(ref Message m)
{

            Console.WriteLine("HWnd: " + m.HWnd.ToString());
            Console.WriteLine("LParam: " + m.LParam.ToString());
            Console.WriteLine("WParam: " + m.WParam.ToString());
            Console.WriteLine("Msg: " + m.Msg.ToString());
            int nSize = 514;
            StringBuilder AtomName = new StringBuilder(nSize);
            nSize = GlobalGetAtomName(m.LParam, AtomName, nSize);
            Console.WriteLine("String: " + AtomName);

    base.WndProc(ref m);
}

1 个答案:

答案 0 :(得分:0)

将值转换为所需类型:

(ushort)m.LParam