本文共 1116 字,大约阅读时间需要 3 分钟。
public string DoSomething(string plain, string signatureAlgorithm) { int nRet = 0; IntPtr hSE = new IntPtr(); byte[] bytes = Encoding.Default.GetBytes(plain); int length = bytes.Length; IntPtr destination = Marshal.AllocCoTaskMem(length); Marshal.Copy(bytes, 0, destination, bytes.Length); int cb = 0x800; IntPtr signature = Marshal.AllocCoTaskMem(cb); nRet = DO_SOMETHING(hSE, destination, length, signatureAlgorithm, signature, ref cb); if (nRet != 0) { throw new Exception("NOT OK!", nRet); } byte[] buffer2 = new byte[cb]; Marshal.Copy(signature, buffer2, 0, cb); Marshal.FreeCoTaskMem(destination); Marshal.FreeCoTaskMem(signature); return Convert.ToBase64String(buffer2); } [DllImport("some.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int DO_SOMETHING(IntPtr hSE, IntPtr plain, int plainLen, string signmethod, IntPtr signature, ref int signatureLen);
转载地址:http://gwucn.baihongyu.com/