Java Pointer vs C# IntPtr
Hi have to use a dll. In Java we use this :
Public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)
Native.loadLibrary("are32.dll",
CLibrary.class);
Pointer ENCRYPT(String a, int ai, String b, int bi);
}
...
Pointer ptr1 = CLibrary.INSTANCE.ENCRYPT("TEST",5,"TEST",5);
for (int i=0;i<6;i++)
System.out.println((ptr1.getByte(i)& 0xFF));
Can you help me to find the equivalent in C# please? I used IntPtr but I can't find a ReadByte like Java.
[DllImport("are32.dll",)]
public static extern IntPtr ENCRYPT(string p1, int p2, string p3, int p4);
...
var retPtr = ENCRYPT("TEST", 5, "TEST", 5);开发者_StackOverflow中文版
How Can I ReadByte
from retPtr
? IntPtr
is it equals to Pointer
?
Thanks for your help
use
byte b = System.Runtime.InteropServices.Marshal.ReadByte(retPtr);
you can also fill your 5-byte array with a single call:
const int arrSize = 5;
byte[] arr = new byte[arrSize];
System.Runtime.InteropServices.Marshal.Copy(retPtr, arr, 0, arrSize);
精彩评论