library StrOperation;//(DLL文件) uses SysUtils, Classes; function InStr(SourceStr:PChar;Ch:Char):integer;stdcall; var Len,i:Integer; begin Len := strlen(SourceStr); for i := 0 to len-1 do if SourceStr[i] = ch then begin Result := i; Exit; end; Result := -1; end; exports Instr name 'MyInStr'; //Index 1;// resident; //(这里的INDEX和resident到底是什么意思,我照书上一加就错) begin end. //调用 unit Unit2;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls; function InStr(SourceStr:PChar;Ch:Char):integer; stdcall;external 'StrOperation.dll'; var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); var order : Integer; txt : PChar; PFunc : TFarProc; Moudle: THandle; begin Moudle := Loadlibrary(绝对路径); if Moudle > 32 then begin Pfunc := GetProcAddress(Moudle,'Instr'); txt := StrAlloc(80); txt := StrPCopy(txt,Edit1.Text); Order := TInStr(@Pfunc.txt,@Edit2.txt);//这里不认识DLL里的函数 Freelibrary(Moudle); end; end; end.
对不起,忘了看你的定义了 这里应该是 Order := TInStr(txt,Pchar(Edit2.txt));//这里不认识DLL里的函数
你好象没有引用dll单元啊
function InStr(SourceStr:PChar;Ch:Char):integer;
stdcall;external 'StrOperation.dll';
function InStr(SourceStr:PChar;Ch:Char):integer;
stdcall;external 'StrOperation.dll';
程序就不认识SourceStr了。。
还有就是resident是什么意思??
HELP里没有
大家帮忙~!~
uses
SysUtils,
Classes;
function InStr(SourceStr:PChar;Ch:Char):integer;stdcall;
var
Len,i:Integer;
begin
Len := strlen(SourceStr);
for i := 0 to len-1 do
if SourceStr[i] = ch then
begin
Result := i;
Exit;
end;
Result := -1;
end; exports
Instr name 'MyInStr'; //Index 1;// resident;
//(这里的INDEX和resident到底是什么意思,我照书上一加就错)
begin
end.
//调用
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;
function InStr(SourceStr:PChar;Ch:Char):integer;
stdcall;external 'StrOperation.dll';
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
order : Integer;
txt : PChar;
PFunc : TFarProc;
Moudle: THandle;
begin
Moudle := Loadlibrary(绝对路径);
if Moudle > 32 then
begin
Pfunc := GetProcAddress(Moudle,'Instr');
txt := StrAlloc(80);
txt := StrPCopy(txt,Edit1.Text);
Order := TInStr(@Pfunc.txt,@Edit2.txt);//这里不认识DLL里的函数
Freelibrary(Moudle);
end;
end;
end.
这里应该是
Order := TInStr(txt,Pchar(Edit2.txt));//这里不认识DLL里的函数
type function InStr(SourceStr:PChar;Ch:Char):integer;stdcall;
//然后取得dll的句柄
Moudle := Loadlibrary(绝对路径\x.dll);if Moudle > 32 then
begin
//取得函数地址
Pfunc := GetProcAddress(Moudle,'Instr');
txt := StrAlloc(80);
txt := StrPCopy(txt,Edit1.Text);
Order := TInStr(@Pfunc.txt,@Edit2.txt);//这里不认识DLL里的函数
Freelibrary(Moudle);
end;
1。如果静态引入dll文件中的函数,需要在函数引用时用function InStr
SourceStr:PChar;Ch:Char):integer;
stdcall;external 'StrOperation.dll';
2。如果动态的引入函数,可以通过定义一个类型function(有待确定),象调用过程一样。
type
TINStr=function(source:pchar;check:char):integer;