本帖最后由 A_cool 于 2009-11-04 17:57:51 编辑

解决方案 »

  1.   

    这个嘛 那个嘛 什么嘛~~~~~~~~
    试下这样var
      MyChar:Pchar;  new(MyChar);
      StrPCopy(Mychar,userId);
      读的话用  StrPas(Pchar);返回string 感觉delphi的强制类型转换很有问题,  记得转换前记得把string trim下 
      

  2.   

    如果是D2009以上的版本把PChar改成PAnsiChar
      

  3.   

    charUserId, charPwd, charProxy: Pchar; 先给这几个分配足够的空间
      

  4.   

    感谢jiap1723(风之谷)和preserve(叶孤枫),综合你们两个人给的方法问题已经解决。<span style="color:#FF0000"><strong>解决方法如下:</strong></span
    1、Delphi9使用PAnsiChar才能够与C++的char*对应
       TRegister = function(userId, proxy, pwd: PAnsiChar): Integer; cdecl; 
    2、defphi PAnsiChar变量赋值之前需要new(charUserId )<span style="color:#FF0000"><strong>下面代码测试通过:</strong></span>
    function TPhoneDllLoader.telRegister(userId, pwd, proxy: string): Integer;
    var
      telRegisterFunc: TRegister;
      outcome: Integer;  charUserId, charPwd, charProxy: PAnsiChar;
    begin
      new(charUserId);
      new(charPwd);
      new(charProxy);  StrPCopy(charUserId,userId);
      StrPCopy(charPwd,pwd);
      StrPCopy(charProxy,proxy);
      if hDLL <> 0 then
      begin
        telRegisterFunc := GetProcAddress(hDLL, 'registe');
        outcome := telRegisterFunc(charUserId, charProxy, charPwd);
        if outcome <> 0 then
        begin
          ShowMessage('registe process error.');
        end;
      end;
    end;
      

  5.   

    程序修正:
    function TPhoneDllLoader.telRegister(userId, pwd, proxy: AnsiString): Integer;
    var
      telRegisterFunc: TRegister;
      outcome: Integer;  charUserId:^PAnsiChar;
      charProxy: ^PAnsiChar;
      charPwd: ^PAnsiChar;
    begin
      New(charUserId);
      charUserId^ := PAnsiChar(userId);  New(charPwd);
      charPwd^ := PAnsiChar(pwd);  New(charProxy);
      charProxy^ := PAnsiChar(proxy);  if hDLL <> 0 then
      begin
        telRegisterFunc := GetProcAddress(hDLL, 'registe');
        outcome := telRegisterFunc(charUserId^, charProxy^, charPwd^);
        if outcome <> 0 then
        begin
          ShowMessage('registe process error.');
        end;
      end;  Dispose(charUserId);
      Dispose(charPwd);
      Dispose(charProxy);
    end;