api函数是这样的:
BOOL WINAPI EncryptStringFun1(
LPCTSTR lpInBuffer,
LPCTSTR lpKey,
LPTSTR lpOutBuffer
);
这是一个加密程序,显然最后一个参数 lpOutBuffer 需要ref出来,但是屡试不爽
不知道参数定义该怎么写!

解决方案 »

  1.   

    try StringBuilder instead, see an example herehttp://msdn.microsoft.com/msdnmag/issues/02/08/CQA/using System.Text; // for StringBuilder
    public class Win32 {
      [DllImport("user32.dll")]
      public static extern int GetWindowText(int hwnd,
        StringBuilder buf, int nMaxCount);
    }
    then useStringBuilder sb = new StringBuilder(1024);and pass sb into the method
      

  2.   

    我也遇到同样的问题;
    在powerbuilder中申明为
    Function boolean MD5File(ref string filename, ref string outstr, long outlen) library "lib_fun.dll"
    可以用,我想将它用在C#里,不知怎么用?请高手帮忙!///声明API函数
    [DllImport"lib_fun.dll",EntryPoint="MD5String",ExactSpelling=false,CharSet=CharSet.Unicode, SetLastError=true)]  static extern bool MD5String ([MarshalAs(UnmanagedType.LPStr)]  string   instr,Int32 inlen, [MarshalAs(UnmanagedType.LPStr)]  string  outstr, Int32 outlen ); 
    上述代码编译可通过,但得不到结果.