现有有一个写好的C语言 DLL 部分代码如下 实现的功能为读取E盘目录下一个.mat文件的长度
unsigned int ReadMatSize(char *path){
FILE *fp=NULL;
char buffer[BUFFER_SIZE]={0};
unsigned int size=0; fp=fopen(path,"rb"); if (fp==NULL){
printf("Fail to open file!\n");
fclose(fp);
return(255);
} fread(buffer,1,188,fp);
clear_buffer(buffer,BUFFER_SIZE);
fread(buffer,1,4,fp);
size=bytes2int(buffer);
size/=8;
return(size);
现在使用Delphi 调用这个DLL 采用的是隐式调用的方法
unit MatRead;
interface
type
PChar=^AnSiChar;
function ReadMatSize(path:PChar):Integer;cdecl;
implementation
function ReadMatSize;external 'MatReadLib.dll' name 'ReadMatSize';
end.
unit main;interfaceuses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
uses
MatRead;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
s:AnsiString;
P:PChar;
size:Integer;
begin
s:='E:\\test.mat';
p:=PChar(s);size:=ReadMatSize(P);end;end.
应该有的效果是点击按钮 完成调用 但是编译不出错 无结果 无弹窗 size:=ReadMatSize(p);始终无法完成调用
unsigned int ReadMatSize(char *path){
FILE *fp=NULL;
char buffer[BUFFER_SIZE]={0};
unsigned int size=0; fp=fopen(path,"rb"); if (fp==NULL){
printf("Fail to open file!\n");
fclose(fp);
return(255);
} fread(buffer,1,188,fp);
clear_buffer(buffer,BUFFER_SIZE);
fread(buffer,1,4,fp);
size=bytes2int(buffer);
size/=8;
return(size);
现在使用Delphi 调用这个DLL 采用的是隐式调用的方法
unit MatRead;
interface
type
PChar=^AnSiChar;
function ReadMatSize(path:PChar):Integer;cdecl;
implementation
function ReadMatSize;external 'MatReadLib.dll' name 'ReadMatSize';
end.
unit main;interfaceuses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
uses
MatRead;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
s:AnsiString;
P:PChar;
size:Integer;
begin
s:='E:\\test.mat';
p:=PChar(s);size:=ReadMatSize(P);end;end.
应该有的效果是点击按钮 完成调用 但是编译不出错 无结果 无弹窗 size:=ReadMatSize(p);始终无法完成调用
还有调用约定你得注意下,这个你看看你这个dll工程 如果没有特别强调VS默认应该是这个 但是建议改为stdcall