本帖最后由 zshsuming 于 2009-12-10 09:13:36 编辑

解决方案 »

  1.   

    k:=SSSendBuffer(0,@StrParam,PChar(Memo1.Lines.Text),false); 
    StrParam变量分配空间了吗?
    应该用Create之类的函数实例对象吧
    期待高手指点!
      

  2.   

    俺试了一下,应该这样使用:var
      StrParam: PFileParam;New(StrParam);
    k:=SSSendBuffer(0,@StrParam,PChar(Memo1.Lines.Text),false); 
    Dispose(StrParam);
      

  3.   

    StrParam:TFileParam; 
    这是一个栈内存,本身就已经分配了一个结构体的大小,还需要如何分配内存?
      

  4.   

    分配了,StrParam:TFileParam; 
    这样后编译器会自己帮你分配StrParam的内存(如果StrParam:PFileParam;这样是指针才需要自己用new分配).
    你的代码看起来没错,你可以试一下先初始化一下StrParam,如下:
          Fillchar(StrParam,sizeof(TFileParam),#0);//初始化
          StrParam.effect:=8; 
          StrParam.Font:=16; 
          StrParam.ShowTitle:=0; 
          StrParam.TitleColor:=2; 
          StrParam.WordColor:=0;       k:=SSSendBuffer(0,@StrParam,PChar(Memo1.Lines.Text),false); 
          //。
     
    如果还不行在结构声明添加packed关键字试一下,如下:FileParam=packed record 
        effect:Byte; 
        level:Byte; 
        Speed:Byte; 
        Delay:Byte; 
        Font:Byte; 
        ShowTitle:Byte; 
        TitleColor:Byte; 
        WordColor:Byte; 
      end; 
      

  5.   

    整个结构体就刚好是8个字节,应该不会有程序刻意采用16byte对齐吧?
      

  6.   

    不清楚楼主所使用的是什么版本的Delphi,建议将函数定义由:
    TSSSendBuffer=function(Index:Integer;Param:PFileParam;StrBuffer:PChar;Flag:Boolean):Integer;stdcall;
    修改为:TSSSendBuffer=function(Index:Integer;Param:PFileParam;StrBuffer:PAnsiChar;Flag:Boolean):Integer;stdcall;
      

  7.   

    不好意思,我用的是D2007,XP平台
      

  8.   

    唯一有可能有问题的地方就是 bool 的声明
    c 标准里是没有 bool 类型的,c++ 里才有。因为我不懂 cpp,所以不知道 bool 是1字节还是4字节。但在 c 中 BOOL 一般是定义成和 int 一样宽的,32位平台中也就是4字节。
    而 delphi 中的 Boolean 是1字节,如果 cpp 中的 bool 也是1字节的话那什么问题都没有,否则在传参数之前不会先 movzx eax, al,而是直接 push eax,这样就很可能导致原本为 True 的参数实际上传成了 FALSE
      

  9.   

    这样子看唯一可能有差异的就是C++里面的函数定义:
    extern "C" __declspec(dllexport) int __stdcall SS_Send_Buffer(int W_index,TFileParam *param,const char *Buffer,bool IsSave); 
    会不会是
    extern "C" __declspec(dllexport) int __stdcall SS_Send_Buffer(int W_index,TFileParam *param,const char *Buffer,BOOL IsSave); 
    如果是后者,那就将Delphi当中的定义修改为:TSSSendBuffer=function(Index:Integer;Param:PFileParam;const StrBuffer:PAnsiChar;Flag:LongBool):Integer;stdcall;
      

  10.   

    刚才不小心说反了,True 不会变成 FALSE,而是 False 很可能变成非0……