dll与主程序的通讯 [英] dll to main program communication

查看:77
本文介绍了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.

推荐答案

您的主程序应导出一个日志记录功能,并使DLL知道该功能.您的DLL需要导出一个函数(例如InitLogging),该函数需要一个函数指针并将传递的值存储在其全局数据中的某个位置.

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.

另一种选择是将您的主"程序放在另一个DLL中,并创建一个将所有DLL链接在一起的存根"主程序.

An alternative is to put your "main" program in another DLL and make a "stub" main that links all the DLLs together.

(在Windows上,DLL可以调用彼此的函数,但是DLL无法在主程序中调用函数.在Unix上,这要简单得多,因为共享库可以直接调用主程序的函数.)

(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.)

这篇关于dll与主程序的通讯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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