dll如何与可执行文件通信 [英] how dll communicate with executable

查看:80
本文介绍了dll如何与可执行文件通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我在网站上找不到答案,如果有人知道请澄清,



DLL和Executable在同一台机器上运行,dll已向可执行的问题发送消息以完成该过程(例如:从dll加载数据/资源)。



DLL如何贴近可执行文件?







问候,

Ranjith

Hi there,

I could not find the answer in websites, if any body knows please clarify,

DLL and Executable are running in same machine and dll has send message to executable regards to completed the process(ex: Loading data/resource from dll).

How DLL can intimate the executable?



Regards,
Ranjith

推荐答案

您可以使用Mike所描述的内容(回调)...但如果这是针对Windows的......我会使用Windows消息。为什么? ...因为一旦你弄清楚了这个技术,就可以轻松添加/删除消息而无需更改DLL接口(取决于你是否关心改变DLL接口)。



这是一篇关于使用MFC的Windows消息的文章,但是如果你没有使用MFC,你也可以通过原始的WinAPI来做(并且它也很容易这样做):

http://msdn.microsoft.com/en-us/library/6d1asasd.aspx [ ^ ]
You can use what Mike described (callback)... but if this is for Windows... I'd use Windows messages. Why? ...because once you have figured out the technique, it's easy to add/remove messages without changing the DLL interface (depends on whether you care about a changing a DLL interface or not).

Here's an article about Windows messages with MFC, but if you're not using MFC, you can also do it through the raw WinAPI (and it's pretty easy to do so as well):
http://msdn.microsoft.com/en-us/library/6d1asasd.aspx[^]


代码是在进程内的DLL还是EXE中是没有意义的。重要的是,您有两个必须相互通信的进程。我假设通信不必使用异步消息传递(消息传递,即:两个进程都在运行时必须进行沟通。



在这种情况下,你必须选择并使用IPC机制: Windows进程间通信

列出的windows IPC机制中最基本的两种通信方法是管道和插座。

我个人最喜欢的是套接字,因为:

- 很容易移植到任何平台

- 易于运行的流程在单独的机器上和通信代码仍然是相同的

- 在用不同语言编写的程序之间易于使用

- 环回通信(当两个端点在同一台机器上时)在所有主要平台上进行优化,因此在本地使用套接字与使用套接字一样有效管道
It is meaningless whether the code is in a DLL or an EXE inside the processes. The important thing is that you have two processes that have to communicate with each other. I assume that the communication doesn't have to use async message passing (Message passing, i.e.: both processes are running when the communication has to be performed.

In this case you have to choose and use an IPC mechanism: Windows Interprocess Communications
The two most basic communication methods from the listed windows IPC mechanisms are pipes and sockets.
My personal favorite is sockets because:
- Its easy to port to any platform
- Easy to run the processes on separate machines and communciation code is still the same
- Easy to use it between programs written in different languages
- loopback communication (when both endpoints are on the same machine) is optimized on all major platforms so using sockets locally is as effective as using pipes


使用回调。



请参阅此文章以获取示例: C ++中的类型安全回调 [ ^ ]


这篇关于dll如何与可执行文件通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆