开发者

IntPtr to String and long?

I am using C# and the .NET 2.0 framework.

I have this method here to get a string out of a IntPtr:

 void* cfstring = __CFStringMakeConstantString(StringToCString(name));
        IntPtr result = AMDeviceCopyValue_Int(device, unknown, cfstring);
        if (result != IntPtr.Zero)
        {
            byte length = Marshal.ReadByte(result, 8);
            if (length > 0)
            {
                string s = Marshal.PtrToStringAnsi(new IntPtr(result.ToInt64() + 9L), length);
                return s;
            }
        }
        return String.Empty;

It works and all data which is saved as string in my USB-Device (return data of method AMDeviceCopyValue).

Now I get this:

£\rº\0\0¨\t\0\0\0ˆ\0\0\0\0\0\0x>Ô\0\0\0\0Ũ\t\0\0\0€1ÔxÕ͸MÔ\0\0\0\0Ȩ\t\0\0\0€)\0fŒ\a\0Value\0\0˨\t\0\0\0€7fŒ\a\0Result\0Ψ\t\0\0\0ˆTÅfŒ\a\0\0Key\0\0\0\0ñ¨\t\0\0\0€+fŒ\a\0Port\0\0\0ô¨\t\0\0\0€%fŒ\a\0Key\0\0\0\0÷¨\t\0\0\0€:\0\0\0\0\0\0\0\0\开发者_如何学编程0\0\0\0\0\0ú¨\t\0"

This is saved as long - so, how I can get this IntPtr into long and not string?


If you simply want to read a long instead of a string, use:

long l = Marshal.ReadInt64(result, 9);
return l;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜