我写了个简单的dll例子,以熟悉dll编程。
example.dll源码如下:
library example;uses
SysUtils,
Classes;
{$R *.res}
function InStr(SourceStr: integer;Ch: Char): Integer; export;
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 ;begin
end.
////////////////////////////////
在下面的代码中动态调用 example.dll,但不知为什么,程序最后总是提示’ access violation at 0X000000 read of address 0x000000'
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TInStr = function(Source: integer;Check: Char): Integer;stdcall;
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
moudle:Thandle;
fun:farproc ;
order: Integer;
aa:pchar;
begin
moudle := loadlibrary('example');
if moudle >32 then begin
fun:=getprocaddress(moudle,'Instr');
//aa:=stralloc(80);
//aa:=strpcopy(aa,edit1.text);
order:=TInStr(fun)(strtoint(self.Edit1.text),'c');
// showmessage(inttostr(order));end;
freelibrary(moudle);
end;end.请帮我找找原因,谢谢!另外我想问一下,是不是在dll中处理字符串不大方便?
example.dll源码如下:
library example;uses
SysUtils,
Classes;
{$R *.res}
function InStr(SourceStr: integer;Ch: Char): Integer; export;
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 ;begin
end.
////////////////////////////////
在下面的代码中动态调用 example.dll,但不知为什么,程序最后总是提示’ access violation at 0X000000 read of address 0x000000'
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TInStr = function(Source: integer;Check: Char): Integer;stdcall;
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
moudle:Thandle;
fun:farproc ;
order: Integer;
aa:pchar;
begin
moudle := loadlibrary('example');
if moudle >32 then begin
fun:=getprocaddress(moudle,'Instr');
//aa:=stralloc(80);
//aa:=strpcopy(aa,edit1.text);
order:=TInStr(fun)(strtoint(self.Edit1.text),'c');
// showmessage(inttostr(order));end;
freelibrary(moudle);
end;end.请帮我找找原因,谢谢!另外我想问一下,是不是在dll中处理字符串不大方便?
解决方案 »
- 如何把一个按钮的Enabled和DBNavigator中的一个按钮相关联?
- ADOTalbe+DBChart生成柱形图,柱的颜色的问题?
- 请问FastReport中表单合计怎么做?
- 请问如果查找成功怎么代码写入数据表aa呀,并且怎么样写代码把表字段显示在界面上,谢谢了
- dbgrid显示问题(菜鸟问题,进来拿分),十分火急!!!!!!!
- 第一次用TADOQuery,迷惑中!!!
- 请教静音问题
- oracle 存储过程返回游标调用
- 如何在Delphi6中使用Vararrayof
- $120: info := 'Max Value'; 语句中最前面的$120是什么意思,有什么作用?谢谢...
- Delphi7里面的XPColorMap控件有什么用?
- 在问一个关于多人使用的小型数据库系统
SysUtils,
Classes;
{$R *.res}
function InStr(SourceStr: integer;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 ;begin
end.
library example;uses
ShareMem,
SysUtils,
Classes;
{$R *.res}
function InStr(SourceStr: string;Ch: Char): Integer; stdcall;
SysUtils,
Classes;
{$R *.res}
function InStr(SourceStr: integer;Ch: pChar): Integer; stdcall;字符串一般用pChar类型,如果只是delphi调用直接string就可以!