dll与主程序的通信
我想跟踪 dll 模块中的一些文本到主程序窗口(到日志子窗口)。我怎样才能正确地做到这一点? (通过内核原语,通过从一个窗口到另一个窗口发送消息,传递回调接口?)我见过的工作示例:Matlab 和 Octave。当调用 mexPrintf
时,输出会打印在主窗口中。
I want to trace some text from dll module to a main program window (to a log subwindow). How can I do this correctly? (through kernel primitives, via sending messages from window to window, passing callback interfaces?) The working example I've seen: Matlab and Octave. When calling mexPrintf
then output printed in their main windows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的主程序应该导出一个日志记录函数并让 DLL 知道它。您的 DLL 需要导出一个函数,例如 InitLogging,它接受函数指针并将传递的值存储到其全局数据中的某处。
另一种方法是将“主”程序放在另一个 DLL 中,并创建一个将所有 DLL 链接在一起的“存根”主程序。
(在Windows上,DLL可以调用彼此的函数,但是DLL不能调用主程序中的函数。在unix上,这更简单,因为共享对象可以直接调用主程序的函数。)
Your main program should export a logging function and make it known to the DLL. Your DLL needs to export a function, such as InitLogging, that takes a function pointer and stores the passed value somewhere into its global data.
An alternative is to put your "main" program in another DLL and make a "stub" main that links all the DLLs together.
(On Windows, DLLs can call each other's functions, but a DLL cannot call a function in the main program. On unix, this is much simpler, as shared objects can directly call the main program's functions.)