如何从MFC ext更新MFC对话框。 DLL [英] How to update MFC dialog from MFC ext. Dll

查看:66
本文介绍了如何从MFC ext更新MFC对话框。 DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个基于对话框的MFC应用程序。

I have created a Dialog based MFC application.

我正在从对话框中获取一些用户输入,并且将这些输入写入文件。

I am taking some user inputs from the dialog, and writing those inputs to a file.

然后我使用loadlibrary()方法加载一个dll并使用GetProcAddress我将文件名传递给dll。

Then I load a dll using loadlibrary() method and by using GetProcAddress I am passing the file name to the dll.

Dll读取文件。

稍后对文件数据应用一些业务逻辑/计算。

later apply some business logic/ calculation on the on the file data.

现在问题是我想要的在对话框上显示已处理的数据。

Now the problem is I wants to display the processed data on the Dialog.

预期的行为是,dll应在计算完成后立即将处理后的数据连续发送到对话框。

The expected behavior is,  the dll should send the processed data continuously to the dialog as soon as the calculation is done.

请指导我如何从dll访问MFC应用程序的对话框类。  

Please guide me how can I access the dialog class of the MFC application from a dll.  

我可以使用SendMessage()或PostMessage()API吗?

Can I make use of SendMessage() or PostMessage() API?

我应该将哪些参数传递给这些API。

What parameters should I pass to these APIs.

任何参考源代码也将帮助我理解。

Any reference source  code will also help me a lot to understand.

提前感谢。

谢谢&此致,Mayank Agarwal

Thanks & Regards, Mayank Agarwal

推荐答案

在我看来,如果你传递 HWND,可以使用 SendMessage m_hWnd 成员)对话框的DLL函数作为参数。然后决定消息和参数。您可以使用
WM_APP + N 消息或 RegisterWindowMessage 创建的消息。在MFC中,使用
ON_MESSAGE ON_REGISTERED_MESSAGE 宏来处理消息[ https://msdn.microsoft.com/en-us/library/0812b0wa.aspx ]。

In my opinion, SendMessage can be used if you pass HWND (m_hWnd member) of your dialog to DLL function as a parameter. Then decide regarding the messages and parameters. You can use a WM_APP+N message or one created by RegisterWindowMessage. In MFC, use ON_MESSAGE and ON_REGISTERED_MESSAGE macros to handle the messages [https://msdn.microsoft.com/en-us/library/0812b0wa.aspx].

用法类似于标准信息,即您将根据您的约定传递 HWND ,您的消息代码以及
WPARAM LPARAM ,使用相应的转换。

The usage is similar to standard messages, i.e. you will pass HWND, your message code, and also WPARAM and LPARAM according to your conventions, using the corresponding casting.

PostMessage 也可以使用,确保传递的参数(例如指针)在处理预定的消息之前不会变为无效。

The PostMessage can be used too, ensuring that the passed parameters (e.g. pointers) do not become invalid before processing the scheduled messages.

另一种方法是将指针传递给EXE中定义的静态函数。然后DLL会调用它。在初始化期间将函数的地址和一些相关参数(例如对话框的
指针)传递给DLL。 DLL将保留并使用它们进行通信。 (这类似于"回调"的概念。示例:
EnumWindows 函数的第一个参数)。

The alternative is to pass a pointer to a static function, defined in your EXE. Then DLL will call it. Pass the address of the function, and some associated parameters such as the this pointer of dialog), to DLL during initialization. The DLL will keep and use them for communication. (This is similar to the concept of "callback". Example: the first parameter of EnumWindows function).


这篇关于如何从MFC ext更新MFC对话框。 DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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