web调用dephi的dll,发生《尝试读取或写入受保护的内存。这通常指示其他内存已损坏。》 错误
dephi:
Function Test(out AdvInfo: Pchar; out LenAdvInfo:integer):string; stdcall;
begin
result := '中国人民万岁!';
lenadvinfo:=length('中国人民万岁!');
advinfo:=pchar(UTF8Encode('中国人民万岁!'));
end;
c#:
[DllImport("PrgLISDLL.dll", EntryPoint = "Test", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern int Test(out StringBuilder AdvInfo, out int LenInt);
StringBuilder AdvInfo = new StringBuilder(2048);
int LenInt = 0;
Test(out AdvInfo, out LenInt);
byte[] btXM = Encoding.Default.GetBytes(AdvInfo.ToString());
string sXM = System.Text.Encoding.UTF8.GetString(btXM);
Response.Write(sXM);
发生如下错误:尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
郁闷啊,这个问题困惑我好久了,有没有做过的朋友告诉我怎么做