问题
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.
回答1:
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.)
来源:https://stackoverflow.com/questions/7221776/dll-to-main-program-communication