如何使用从dll运行的应用程序?

编程入门 行业动态 更新时间:2024-10-23 11:25:56
本文介绍了如何使用从dll运行的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用主机应用程序中的数据时遇到问题。 我想通过dll将主机发送一个字符串,然后将其与主机应用程序的某些数据相结合。

Im having problems using data from the host application. I want to send a string through the dll into the host, then combine it with some data from the host app.

只要在使用子句中包含表单,我可以使用方法将数据发送到主机中,当数据被收回时,我尝试添加一个lokal变量,这是当我获得访问冲突:

By just including the form in the uses clauses i can use methods to send data into the host, When the data is recived i try to add a lokal variable, this is when i get a access violation:

主持人:

procedure TMainForm.DllLink(sMessage: String); begin try //This is ok: Showmessage(sMessage); //This is causes Access error: Showmessage(sMessage +sPid); except Showmessage('Access violation'); end; end;

Dll:

procedure Transfer(sMessage: PChar); stdcall; var sMyPid : String; begin try //Get error if i try to use this method to get sPid which is a string: sMyPid := MainForm.GetPid; //Or this: MainForm.NextsysDllLink(sMessage); except showmessage('Error'); end; end;

我不认为dll正在使用正在运行的应用程序表单,这是导致访问冲突的原因(也许是im错误?)如何使DLL知道正在运行的应用程序(即其主机应用程序),并使用该实例来获取或操纵数据本身?

I dont think the dll is using the running applications forms that is what's causing the access violations (maybe im wrong ?) How do I make the dll aware of a running application(that is its host app.) and use that instance to ether get or manipulate data from itself ?

我使用Delphi 5。

Im using Delphi 5.

推荐答案

建议不要在应用程序和DLL边界之间传递本地Delphi对象。 如果你想这样做,你应该使用Packages而不是DLL。

It is recommend to not pass native Delphi Objects between Application and DLL boundaries. If you want to do that you should be using Packages instead of DLLs.

全局变量是应用程序和Dll之间不共享。

Global variables are not shared between application and Dll.

在您的情况下,您引用DLL中的全局 mainform 变量,如果调试该代码,您会发现您的主机应用程序中 mainform = nil或与 mainform 不同的另一个地址。

n your case, your referencing the global mainform variable in the DLL, if you debug that code you will find that mainform = nil or another address that is not the same as the mainform in your host application.

更多推荐

如何使用从dll运行的应用程序?

本文发布于:2023-11-09 05:43:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571529.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   应用程序   dll

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!