//delphi编写的DLL函数
function ReportServer(const ServerTypeParams: TServerTypeParams; var RetValue: PChar;var RetValueLen: Integer): Boolean;stdcall;
//TServerTypeParams结构体的定义
TServerTypeParams= record
ServerType: PChar;
Template: PChar;
DefaultTemplate: PChar;
end;在ASP.net(C#)中调用DLL提出ReportServer函数//对应结构体定义
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi,Pack=1)]
public struct TServerTypeParams
{
[MarshalAs(UnmanagedType.LPStr)]
public string ServerType;
[MarshalAs(UnmanagedType.LPStr)]
public string Template;
}
这样传送过去后delphi里跟踪根本就没有,忘高手指点指点。
//对应结构体定义,上面发帖的时候少黏贴了一个DefaultTemplate
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi,Pack=1)]
public struct TServerTypeParams
{
[MarshalAs(UnmanagedType.LPStr)]
public string ServerType;
[MarshalAs(UnmanagedType.LPStr)]
public string Template;
[MarshalAs(UnmanagedType.LPStr)]
public string DefaultTemplate;
}
function ReportServer(const ServerTypeParams: TServerTypeParams; var RetValue: PChar;var RetValueLen: Integer): Boolean;stdcall;
//TServerTypeParams结构体的定义
TServerTypeParams= record
ServerType: PChar;
Template: PChar;
DefaultTemplate: PChar;
end;
换成这样看看:
TServerTypeParams= Packed record
ServerType: PChar;
Template: PChar;
DefaultTemplate: PChar;
end;
加PACKED后,结构体内成员变量类型大小总和大小是多少那结构体的大小就是就是多少.
所以在asp.net(C#)里的结构体定义应该还是原来的定义.