程序如下:unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type TMB = function(hWnd: HWND; lpText, lpCaption: PChar; uType: UINT): Integer; stdcall; TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
MB: TMB;
inst: LongWord;
public end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
inst := LoadLibrary('user32.dll');
if inst <> 0 then MB := GetProcAddress(inst, 'MessageBoxA');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
t,b: PChar;
begin
t := '标题';
b := '内容';
MB(0, b, t, 0);
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeLibrary(inst); {记得释放}
end;end.编译没有错误,也可以生成出exe文件。 我运行生成的exe文件后出现了异常:project project1.exe raised exception class eaccessvioaltion with message 'access violation at address 00000000. read of address 00000000'.process stopped.use step or run to continue.是什么原因呢? 我的是番茄花园的操作系统。 在源程序里帮我改下,谢谢了!
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type TMB = function(hWnd: HWND; lpText, lpCaption: PChar; uType: UINT): Integer; stdcall; TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
MB: TMB;
inst: LongWord;
public end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
inst := LoadLibrary('user32.dll');
if inst <> 0 then MB := GetProcAddress(inst, 'MessageBoxA');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
t,b: PChar;
begin
t := '标题';
b := '内容';
MB(0, b, t, 0);
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeLibrary(inst); {记得释放}
end;end.编译没有错误,也可以生成出exe文件。 我运行生成的exe文件后出现了异常:project project1.exe raised exception class eaccessvioaltion with message 'access violation at address 00000000. read of address 00000000'.process stopped.use step or run to continue.是什么原因呢? 我的是番茄花园的操作系统。 在源程序里帮我改下,谢谢了!
解决方案 »
- 高分救人!使用spcomm控件和下位机通讯,下面每10ms发一帧数据上来,我如何区分每一帧数据
- 如何返回当前目录下?在线等
- web service 中用web dataModule的问题
- 急:自绘制图形的打印 UP 有分 《200分相送》
- 如何在鼠标所指的一个窗体边框上绘制一个矩形?
- 谁有李维的书!
- 程序退出后,托盘区的图标不能及时消失,大家来看看什么问题
- 再自定義的function,procedure 中是否不能用try結構
- 问题:调用带返回参数的存储过程
- Delphi 如何调用带有安全证书https的Webservice
- 多线程文件传输的问题
- dbgrdh1标题列无法排序,‘sort’无法定义该如何解决呢?
if inst <> 0 then
inst 断点跟下,看是否取到值了,
参数类型换成PAnsiChar试试
写法上唯一不规范的地方是如下,但是虽然不规范,依旧不会有错误procedure TForm1.Button1Click(Sender: TObject);
var
t,b: PChar;
begin
t := '标题';
b := '内容';
MB(0, b, t, 0);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
inst := LoadLibrary('user32.dll');
if inst <> 0 then //MB := GetProcAddress(inst, 'MessageBoxA');
@MB := GetProcAddress(inst, 'MessageBoxA');
end还有就是 查看你Dll 的参数方式 有可能不是 stdcall
对照参数类型
@MB := GetProcAddress(inst, 'MessageBoxA');
t,b: string;
begin
t := '标题';
b := '内容';
MB(0, PChar(b), PChar(t), 0);