DELPHI2007和2009再PChar上的不同(100)

Discussion in '编程心得' started by rocketking, Mar 7, 2009.

  1. ro

    rocketking Member

    Apr 1, 2015
    我用c++buider建立了一个DLL程序,其声明如下:extern "C" declspec(__dllexport) __stdcall void CDLL(int a, int b, int& c ,char* s0, char *s1){ *c=a*b;
    s1=strcpy(s1," Hi ! ");
    s1=strcat(s1,s0);}这个DLL文件再C++Builder和Delphi2007下都可顺利被调用,结果也正确。但再Delphi2009更好调用完后,各参量基本都对,但就是返回的s1不对,中间还有乱码,不知为什么?Delphi中声明如下:procedure CDLL(integer a,b;
    var c:integer;
    PChar s0;
    PChar s1);far;stdcall;external 'CDLL';经过测试D2007和D2009的char类型长度有了变化(由1变成了2),但PChar用得是AnsiChar却没有变化,上面的问题症结究竟何在?
     
  2. 草原骏马

    草原骏马 Member

    Apr 1, 2015
    D2009是基于Unicode的。你把传入的参数和返回的结果,做Unicode和string 或Char的转换就可以了。
     
  3. 风铃夜思雨

    风铃夜思雨 Member

    Apr 1, 2015
    Char改AnsiChar就行了
     
  4. ts

    tseug Member

    Apr 1, 2015
    没用过D2k7,D2k9,难道Delphi的语法都支持这样声明了?procedure CDLL(integer a,b;
    var c:integer;
    PChar s0;
    PChar s1);far;stdcall;external 'CDLL';
     
  5. wr

    wr960204 Member

    Apr 1, 2015
    D2009以前:Char=ansichar;PChar = ^char;D2009:Char=WideChar;PChar = ^Char;你的旧程序声明可以转为procedure CDLL(integer a,b;
    var c:integer;
    s0 , S1 : PAnsiChar);far;stdcall;external 'CDLL';
     
  6. li

    liaj Member

    Apr 1, 2015
    Delphi2009以前的 PChar = PAnsiCharDelphi2009的 PChar = PWideChar