如何从多线程DLL函数向调用者应用程序发送消息?

问题描述:

我正在创建一个用于创建GUI的DLL,这就是我计划它工作的方式:

1.应用程序调用DLL函数创建一个带有按钮的表单

2. DLL在新线程中创建表单(因此应用程序不会卡住)

3.应用程序必须在任何时候显示消息 (不只是一次!)在表单上按下一个按钮< -This就是问题。

现在这让我烦恼:DLL如何向应用程序发送消息,因为就在DLL启动了新线程(对于表单),它向应用程序返回一个值,以便应用程序可以继续它的工作。

任何帮助都将不胜感激。

I am making a DLL for creating GUIs and this is how I have planned for it to work:
1. Application calls the DLL function to create a form with a button on it
2. DLL creates a form in a new thread(so the application doesn't get stuck)
3. Application has to show a message whenever(not just once!) a button is pressed on the form <-This is the problem.
Now this is bugging me: how can the DLL send message to the application, because just right after the DLL started the new thread(for the form), it returned a value to the application so the application could continue it's work.
Any help would be appreciated.

有几种方法可以解决这个问题:



1.将Windows消息发送回主窗体并让主窗口监听它。

2.使用插座,例如UDP将消息发送回主应用程序。

3.直接从DLL显示弹出消息。
Theres a few ways you could solve this:

1. Send a Windows Message back to the mainform and have the mainform listen for it.
2. Use sockets e.g. UDP to send a message back to the main application.
3. Display the popup message directly from the DLL.