有一個VC的DLL,函式說明如下:
BOOLEAN Tuc_EnumTouchScreen(
OUT PCHAR *paths,
OUT INT &count
);
paths
[out]設備路徑陣列。
Handle
[out]設備個數。
========================
C++呼叫范例:
INT deviceCount = 0;
PUCHAR devicePaths[64] = {0};
for (int i=0; i<64; i++)
{
devicePaths[i] = new char[256];
ZeroMemory(devicePaths[i],256);
}
Tuc_EnumTouchScreen(devicePaths, deviceCount);
在DELPHI中,應該如何宣告?
我現在是這樣宣告:
function Tuc_EnumTouchScreen(out paths:PChar;out Handle:Integer):Boolean;stdcall; external 'TucLib.dll' name 'Tuc_EnumTouchScreen';
呼叫是這樣:
procedure TForm1.Button1Click(Sender: TObject);
var
I,count:Integer;
paths: array[0..63] of PChar;
begin
for I := 0 to 63 do
begin
paths[I] := StrAlloc(256);
end;
Tuc_EnumTouchScreen(paths[0],count);
end;
運行提示,無法定位dll程式輸入點,請問高手,應該如何宣告和呼叫。
uj5u.com熱心網友回復:
D7以上版本var
I,count:Integer;
paths: array[0..63] of PAnsiChar;
function Tuc_EnumTouchScreen(out paths:PChar;out Handle:Integer):Boolean;stdcall; external 'TucLib.dll' name 'Tuc_EnumTouchScreen';
->
function Tuc_EnumTouchScreen(paths:PPAnsiChar; Handle:Integer):Boolean;stdcall; external 'TucLib.dll' name 'Tuc_EnumTouchScreen';
呼叫
Tuc_EnumTouchScreen(@paths,Count);
如果paths是動態陣列:
paths: array of PAnsiChar;
SetLength(paths,64);
呼叫
Tuc_EnumTouchScreen(paths,Count);
引數OUT PCHAR *paths是PPAnsiChar
不用OUT修飾符
uj5u.com熱心網友回復:
1,從C函式宣告來看,并沒有__stdcall、__attribute__((stdcall))這種修飾,所以不能假定是stdcall呼叫約定。2,OUT INT &count這是參考引數,也就是Pascal中的變參,應該翻譯為var count: integer
3,不能使用動態陣列作為paths引數,Delphi編譯器對動態陣列引數會隱含傳入一個high bound引數,導致count引數獲取不正確。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/66185.html
