共享内存已更新,但如何传递到控制台? [英] Shared memory updated but how to pass to console?

查看:67
本文介绍了共享内存已更新,但如何传递到控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能不是一个简单的问题,并且我已经有一段时间没有使用C ++编程了,但是我希望每次其他应用程序在共享中更新变量时都能唤醒"控制台Win32控制台应用程序记忆.

我已经创建了一个共享内存dll(在c ++中),我可以使用客户端应用程序"访问和更新并从共享内存中获取数据...但是每次我从客户端"中更新数据时,我都想然后以某种方式唤醒服务器" Win32控制台,然后在该控制台中运行代码以检查并使用新值.我可以通过使用RegisterWindowMessage和PostWindowMessage调用使客户端应用程序相互唤醒,但是显然Win32控制台是不同的,并且我不确定我是否可以尝试这种方式或者是否有明显更好的方式?是否可以从共享内存dll中简单地在控制台应用程序中调用函数?

我希望这是有道理的,我已经以一般的方式提出了这个问题,所以如果有人可以将我引导到最安全,最快捷的方法来进行此操作,那么我可以自己尝试一下,找出是否是最好的方法?

谢谢

标记

This may or may not be an easy question and I have been out of programming in C++ for a while, but I want to be able to "wake up" a console Win32 Console Application each time another application has updated variables in shared memory.

I have already created a shared memory dll (in c++) and I can access and update and get the data from the shared memory with "client applications"...but every time I update the data from the "clients" I would like to then somehow wake a "server" Win32 console and then run code in that console to check and work with the new values. I can make my client applications wake each other via the use of RegisterWindowMessage and PostWindowMessage calls but obviously a Win32 console is different and I''m not sure I can even try this way or if there is an obvious better way? Is it possible to simply call a function in the console application from my shared memory dll?

I hope this makes sense and I have asked the question in a general way so if someone could direct me to the safest, quickest method to do this then I can go away and try and figure it out myself if that is the best way?

Thanks

Mark

推荐答案

获取控制台应用程序以使用 ^ ]函数等待 ^ ]对象(请参见 ^ ]函数).剩下的问题是如何使事件HANDLE进入客户端和服务器进程.这应该可以帮助您入门.在对此技术进行了一些研究之后,请随时提出有关该问题的一些更具体的问题.
Get the console application to use the WaitForSingleObject[^] function to wait on an event[^] object which is signalled (see the SetEvent[^] function) by the client application when it wants to wake the server. The remaining issue is how to get HANDLEs to the event to the client and server processes. This should get you started. Feel free to ask some more specific questions on the problem after you''ve done a little research on this technique.


除了斯蒂芬的答案,我建议使用命名事件:在服务器应用程序中使用CreateEvent并为事件命名.然后在客户端应用程序中,使用具有相同名称的OpenEvent.这允许多个应用程序共享同一事件对象.

不要忘记为此使用线程,否则等待事件只会使您的应用挂起...
In addition to Stephen''s answer, I would suggest to use a named event: use CreateEvent in the server application and give a name to your event. Then in the client application, use OpenEvent with the same name. This allows several applications to share the same event object.

Don''t forget to use threads for that, otherwise waiting for the event would just make your apps hang...


Mark Briscombe写道:
Mark Briscombe wrote:

是否可以从共享内存dll中简单地在控制台应用程序中调用一个函数?

Is it possible to simply call a function in the console application from my shared memory dll?



是的(我们称之为callback),您必须将客户端函数指针传递给DLL,然后后者可以在需要时调用then函数.

EnumWindows函数文档 [



Yes (we call it callback), you have to pass the client function pointer to your DLL, then the latter can then call then function whenever is needed.

EnumWindows function documentation[^] may give you an insight into the callback mechanism.


:)


这篇关于共享内存已更新,但如何传递到控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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