用delphi调用C/C++的dll的双指针类型数据,总是内存地址错误,请各位高人帮忙分析一下,急!谢谢了!调用函数语句如下:
Function viScanf(vi:integer;readFmt:pchar;var params:ppchar):integer;Cdecl;external 'VISA32.DLL';函数返回值应该为‘7.53896E+10,1.000053E+10,2.000000E+10’procedure TForm1.Button4Click(Sender: TObject);var params:ppchar;
begin
  viScanf(vi,'%t',params);                   //' Read the results as a string.
  Label3.Caption:=pchar(paramsr);
  memo1.Text:=pchar(params);
  showmessage(pchar(resuchar));
end;

解决方案 »

  1.   

    用C调用不会出错,还没有其他语言调用的例子,我想主要的问题在DELPHI的双指针PPCHAR的调用上
      

  2.   

    function getTest(info: PPChar): Integer;
    var
      str: PChar;
    begin
      Result := -1;  // 返回错误代码
      try
        str := 'Test';
        // TODO: str业务处理
        Info^ := strAlloc(Length(str) * SizeOf(Char) + 1); // 分配内存空间
        StrCopy(Info^, PChar(str));
        Result := 0;
      except
      end;
    end;
    比如这样的
      

  3.   

    也试过分配内存,也不行!
    procedure TForm1.Button4Click(Sender: TObject); var params:ppchar; 
    begin 
      getmem(params,256);
      viScanf(vi,'%t',params);                  //' Read the results as a string. 
      Label3.Caption:=pchar(paramsr); 
      memo1.Text:=pchar(params); 
      showmessage(pchar(resuchar));
      freemem(params); 
    end; 
      

  4.   

    把viScanf的c的声明贴出来var params:PPChar 对应着c中的 char ***params,八成是你声明的错误
      

  5.   


    如果是雙指針:這裏: 
    Function viScanf(vi:integer;readFmt:pchar;params:ppchar):integer;Cdecl;external 'VISA32.DLL';Function viScanf(vi:integer;readFmt:pchar;var params:pchar):integer;Cdecl;external 'VISA32.DLL';
      

  6.   

    多谢starluck的建议,如下是ViScanf函数的解释,请帮忙分析一下问题出在哪里?viScanf
    Syntax
    viScanf(ViSession vi, ViString readFmt, arg1, arg2,...); Description
    This operation receives data from a device, formats it by using the format string, and stores the data in the arg parameter list. The format string can have format specifier sequences, white space characters, and ordinary characters. Note: VISA functions that take a variable number of parameters (e.g., viPrintf, viScanf, and viQueryf) are not callable from Visual Basic. Use the corresponding viVPrintf, viVScanf, and viVQueryf functions instead.The white characters (blank, vertical tabs, horizontal tabs, form feeds, new line/linefeed, and carriage return) are ignored except in the case of %c and %[]. All other ordinary characters except % should match the next character read from the device.A format specifier sequence consists of a %, followed by optional modifier flags, followed by one of the format codes, in that sequence. It is of the form:%[modifier]format codewhere the optional modifier describes the data format, while format code indicates the nature of data (data type). One and only one format code should be performed at the specifier sequence. A format specification directs the conversion to the next input arg. The results of the conversion are placed in the variable that the corresponding argument points to, unless the asterisk (*) assignment-suppressing character is given. In such a case, no arg is used and the results are ignored.The viScanf function accepts input until an END indicator is read or all the format specifiers in the readFmt string are satisfied. It also terminates if the format string character does not match the incoming character. Thus, detecting an END indicator before the readFmt string is fully consumed will result in ignoring the rest of the format string. Also, if some data remains in the buffer after all format specifiers in the readFmt string are satisfied, the data will be kept in the buffer and will be used by the next viScanf function.There is a one-to-one correspondence between % format conversions and arg parameters in formatted I/O read operations except: If a * is present, no arg parameters are used.If a # is present instead of field width, two arg parameters are used. The first arg is a reference to an integer (%c, %s, %t, %T). This arg defines the maximum size of the string being read. The second arg points to the buffer that will store the read data.If a # is present instead of array_size, two arg parameters are used. The first arg is a reference to an integer (%d, %f) or a reference to a long integer (%b, %y). This arg defines the number of elements in the array. The second arg points to the array that will store the read data.If a size is present in field width for the %s, %t, and %T format conversions in formatted I/O read operations either as an integer or a # with a corresponding arg, the size defines the maximum number of characters to be stored in the resulting string.For ANSI C compatibility the following conversion codes are also supported for input codes. These codes are 'i,' 'o,' 'u,' 'n,' 'x,' 'X,' 'e,' 'E,' 'g,' 'G,' 'p,' '[...],' and '[^...].' For further explanation of these conversion codes, see the ANSI C Standard.If viScanf times out, the read buffer is cleared before viScanf returns. When viScanf times out, the next call to viScanf will read from an empty buffer and force a read from the device. The following tables describe optional modifiers that can be used in a format specifier sequence.
      

  7.   

    也使用过在函数声明时将PPCHAR修改为PCHAR这种参数,但是一直报出数据类型不匹配
    Function viScanf(vi:integer;readFmt:pchar;var params:pchar):integer;Cdecl;external 'VISA32.DLL';
      

  8.   

    本帖最后由 hongqi162 于 2009-08-20 11:57:02 编辑
      

  9.   

    本帖最后由 hongqi162 于 2009-08-20 11:57:33 编辑
      

  10.   

    本帖最后由 hongqi162 于 2009-08-20 11:58:08 编辑
      

  11.   

    问题已经解决, 多谢Seamour的提醒,将函数调用时的
    Function viScanf(vi:integer;readFmt:pchar; var params:pchar):integer;Cdecl;external 'VISA32.DLL';
    修改为:
    Function viScanf(vi:integer;readFmt:pchar;params:pchar):integer;Cdecl;external 'VISA32.DLL';
    就可以了procedure TForm1.Button4Click(Sender: TObject); 
    var buf:pchar;
    begin
       getmem(buf,255);
       viScanf(vi,'%t',buf);
       memo1.Text:=pchar(buf);
       freemem(buf);
    end;
      

  12.   

    本帖最后由 hongqi162 于 2009-08-20 11:58:33 编辑