用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;
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;
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;
比如这样的
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;
如果是雙指針:這裏:
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';
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.
Function viScanf(vi:integer;readFmt:pchar;var params:pchar):integer;Cdecl;external 'VISA32.DLL';
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;