//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里跟踪根本就没有,忘高手指点指点。

解决方案 »

  1.   


    //对应结构体定义,上面发帖的时候少黏贴了一个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;
            }
      

  2.   

    //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;
    换成这样看看:
      TServerTypeParams= Packed record
        ServerType: PChar;
        Template: PChar;
        DefaultTemplate: PChar;
      end;
      

  3.   

    这个我是想到了,关键是在asp.net(C#)里的结构体怎么定义。
      

  4.   

    不加PACKED的作用是边界对齐,加快访问速度.如果结构体内成员变量类型大小总和是5,那这个结构体的大小就是6(可能是8,我忘了,反正是增大了).
    加PACKED后,结构体内成员变量类型大小总和大小是多少那结构体的大小就是就是多少.
    所以在asp.net(C#)里的结构体定义应该还是原来的定义.