利用Delphi呼叫C的dll代碼如下
unit MatRead;
interface
type
Pchar=^AnsiChar;
function ReadMatSize(path :PChar):Integer; cdecl;
implementation
function ReadMatSize;external 'MatReadLib.dll' name 'ReadMatSize';
end.
unit main;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Testmat: TButton;
procedure TestmatClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Tdata:PDouble;
implementation
{$R *.dfm}
uses
MatRead;
procedure TForm1.TestmatClick(Sender: TObject);
var
s:AnsiString; arrChar:array[1..1024] of Char; P:PChar;
begin
s:='E:\\test.mat'; p:=PChar(s);
size := ReadMatSize(p);
end;
end.
{size := ReadMatSize(p);}這行代碼出錯 出錯提示為[dcc32 Error] main.pas(33): E2029 '(' expected but ':=' found
uj5u.com熱心網友回復:
你這里Size是啥?uj5u.com熱心網友回復:
你是指編譯出錯吧 size:integer 你都沒定義呢。pchar型別 delphi自帶 不用定義
你的呼叫約定是 cdecl 這個要與dll開發方約定 通常的是 stdcall
uj5u.com熱心網友回復:
這個size 是定義的一個變數啊用來記錄長度的
uj5u.com熱心網友回復:
這讓我說啥好, 你都知道要用size這個變數 干什么 ,你就不能定義一下嗎 就加一句 size:Integer;
procedure TForm1.TestmatClick(Sender: TObject);
var
s:AnsiString;
arrChar:array[1..1024] of Char; P:PChar;
size:Integer;
begin
s:='E:\\test.mat'; p:=PChar(s);
size:=ReadMatSize(p);
end;
uj5u.com熱心網友回復:
Size是系統關鍵字,不能定義做他用的吧?uj5u.com熱心網友回復:
size不是關鍵字吧, sizeof才是,他這個問題很簡單就是沒定義 我都貼代碼了親測
uj5u.com熱心網友回復:
size 這個錯誤是我沒注意 這個程式的問題是我RUN之后 顯示編譯成功 但是既沒有彈窗更沒有結果
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/100401.html
標籤:語言基礎/算法/系統設計
下一篇:delphi操作excel
