调用dll出现'Invalid Pointer operation',怎么回事?

Lion_sj 2003-08-18 06:13:50
如果调用程序和dll都带包编译,出现此错误

如何只有一方或者都不带包编译,没有此错误

而实际需求需要带包编译?

源码如下:
dll:
library wz_lld;

uses
ShareMem,
windows,
SysUtils,
forms,
Db,
DBTables,
unt_wz_lld in 'unt_wz_lld.pas' {Frm_wz_lld},
unt_wz_lld_pnt in 'unt_wz_lld_pnt.pas' {Frm_wz_lld_pnt},
unt_function in '..\unt_function.pas';

function ShowChild(App:TApplication;
DbUser:ShortString;DbPassword:ShortString;BdeAls:ShortString;
ASsdw:ShortString;AUserId:ShortString;Abhdwdm,Abh:shortstring
;AScrollBox:TScrollBox):integer;stdcall;
begin
ssdw := ASsdw;
userid := AUserId;
lldh := Abh;
llddwdm:=Abhdwdm;
Application:=App;
Application.Handle := app.Handle;
if not assigned(frm_wz_lld) then
frm_wz_lld := TFrm_wz_lld.Create(Application);
with Frm_wz_lld do
begin
{ BorderStyle := bsNone;
BorderIcons := [];
// align := alClient;
// WindowState:=wsMaximized;
Windows.SetParent(Handle, AScrollBox.Handle);
windows.MoveWindow(Handle, 0, 0, AScrollBox.Width,AScrollBox.Height, True); }
show;
end;
Result:= Frm_wz_lld.Handle;
// Result:=(TFrm_wz_lld.Create(Application)).handle;
end;
{Function: Set Dll-Application Var back to originall Value}

procedure SetOldApplication;stdcall;
begin
Application:=OldApp;
end;

{$R *.RES}
exports ShowChild,SetOldApplication;
begin
{Save original Applicatioin Variable}
OldApp:=Application;
end.

调用程序:(部分)
TF_ShowChild = function (App:TApplication;
DbUser:ShortString;DbPassword:ShortString;BdeAls:ShortString;
ASsdw:ShortString;AUserId:ShortString;Abhdwdm,Abh:shortstring
;AScrollBox:TScrollBox):integer;stdcall;

function TFrm_wz_lldcl.getDisposalDLLName: string;
begin
result := 'wz_lld.dll';
end;

procedure TFrm_wz_lldcl.LoadDLL(DLLName: string);
var
LastError:DWord;
begin
if dllModHandle_= 0 then
begin
dllModHandle_:=loadLibrary(pchar(DLLName));
if dllModHandle_ =0 then
begin
LastError := GetLastError;
Raise EDLLLoadError.create(IntToStr(LastError) + ': DLL不存在');
end;
ShowChild:=getProcAddress(dllModHandle_,'ShowChild');
if @showChild=Nil then begin
Raise EDLLLoadError.create(IntToStr(LastError) + ': 不能够找到函数 ShowChild');
end;
SetOldApplication:=getProcAddress(dllModHandle_,'SetOldApplication');
if @SetOldApplication=Nil then begin
Raise EDLLLoadError.create(IntToStr(LastError) + ': 不能够找到函数 SetOldApplication');
end;
end;
end;

procedure TFrm_wz_lldcl.sptnDisposalClick(Sender: TObject);
var
DLLName:string;
i:integer;
begin
if stgGrid.Cells[1,stgGrid.Row] = '' then exit;
ScrollBox1.BringToFront;
ScrollBox1.Align := alClient;
Pnl_main.SendToBack;
DLLName := getDisposalDLLName;
LoadDLL(DLLName);
i:=ShowChild(Application,'','','dBAlias_ND',
ssdw,Userid,stgGrid.cells[1,stgGrid.Row],stgGrid.cells[2,stgGrid.Row],ScrollBox1);
end;

procedure TFrm_wz_lldcl.FormDestroy(Sender: TObject);
begin
arrField := nil;

if dllModHandle_<>0 then
begin
SetOldApplication;
FreeLiBrary(dllModHandle_);
end;
end;
...全文
189 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
reedseutozte 2003-08-20
  • 打赏
  • 举报
回复
在dpr文件中加一个引用单元:
sharemem
overtime 2003-08-19
  • 打赏
  • 举报
回复
在你调用的这个工程文件中也加上sharemem,而且是第一位,应该问题解决
qiume 2003-08-19
  • 打赏
  • 举报
回复
用PChar替换掉string,
这样的话不但问题可以解决,
而且DLL更通用
dageming 2003-08-19
  • 打赏
  • 举报
回复
顶,但凡我DLL中有ShareMem就有这样的错
Lion_sj 2003-08-19
  • 打赏
  • 举报
回复
没有人回答吗

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧