本帖最后由 x350023173 于 2011-04-07 09:17:44 编辑

解决方案 »

  1.   


    [DllImport("CreateGWLicense.dll")]
    public static extern IntPtr fnCreateGWLicense(string key, int KeyLen, ref int BufLen);
    //..............
    IntPtr result = fnCreateGWLicense(key, keylen, ref buflen)
    string s = Marshal.PtrToStringAuto(result, buflen);
    或者
    byte[] b = new byte[buflen];
    Marshal.Copy(result, b, 0, buflen);
      

  2.   


    执行这句代码的时候IntPtr result = fnCreateGWLicense(key, keylen, ref buflen)报错!
    对 PInvoke 函数“ConsoleApplication.PInvoke!ConsoleApplication.PInvoke.Program::fnCreateGWLicense”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。
      

  3.   


    [DllImport("CreateGWLicense.dll")]
            [return: MarshalAs(UnmanagedType.LPArray, SizeConst = 8)]
            public static extern IntPtr fnCreateGWLicense(ref StringBuilder key, int KeyLen, ref int BufLen);        static void Main(string[] args)
            {
                StringBuilder key = new StringBuilder();
                key.Append("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
                int keylen = key.Length;
                int buflen = key.Length;            IntPtr result = fnCreateGWLicense(ref key, keylen, ref buflen);
                string s = Marshal.PtrToStringAuto(result, buflen);
            }
    这样修改了还是包错!
     IntPtr result = fnCreateGWLicense(ref key, keylen, ref buflen);
    无法封送处理“return value”: 无效的托管/非托管类型组合(Int/UInt 必须与 SysInt 或 SysUInt 成对出现)。