delphi中调用DLL时编译无问题,运行时报告EAccessViolation,急问如何解决(100分)

  • 主题发起人 主题发起人 ganyu
  • 开始时间 开始时间
G

ganyu

Unregistered / Unconfirmed
GUEST, unregistred user!
以上Dll使用delphi写的。同时自己用VC++写了一个activex控件,在调用其属性时,编译时无错,运行时同样报告非法访问。
 
倒!拜托老大问问题说清楚一点!
你这怎么写谁知道是怎么回事了!
 
不管是哪里出了错,可以肯定的是 一定是什么地方访问越界了,就是资源还没创建或已经
被删除了,却还要访问,就出错了
 
我做了个例子,请各位指教。
DLL代码如下:
library DllExample;

uses
SysUtils,
Classes,
Graph in 'Graph.pas';

exports
ChangeSqlString;

{$R *.RES}

begin
end.
----------------
和unit Graph;

interface

uses
Windows, Messages, Classes, Graphics, Dialogs;

function ChangeSqlString(str:string):string;export;

implementation

function ChangeSqlString;
begin
result:='it is changed.';
end;

end.

调用DLL例子程序如下:
program Project2;

uses
Forms,
Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
-------------------------
和unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus;

type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
test1: TMenuItem;
procedure test1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.test1Click(Sender: TObject);
var
sqlstr : string;
str:string;
DllName:string;
Buffer:array[0..127] of char;
Lib:Thandle;
ChangeSqlString:function(str:string):string;

begin
sqlstr := 'select count(*) from dict_code where par';
DllName:='DllExample.dll';
StrPCopy(Buffer,DllName);
Lib:=LoadLibrary(Buffer);
if Lib<>0 then
try
ChangeSqlString:=GetProcAddress(Lib,'ChangeSqlString');
str:=ChangeSqlString(sqlstr);
ShowMessage(str);
finally
FreeLibrary(Lib);
ShowMessage('fdghdf');
end
else
ShowMessage('load dll error');
end;
end.
 
接受答案了.
 
后退
顶部