如何实现Unmanaged C ++ dll和C#dll之间的实时通信?

如何实现Unmanaged C ++ dll和C#dll之间的实时通信?

问题描述:

问题BackGroud:



最近,我开发了一个.Net加载项应用程序,这个加载项在VS2010启动后加载到VS2010中。



当我用VS2010打开一个C ++项目时,我需要调试这个C ++项目。但是,这个c ++项目将调用一个Unmanaged C ++ dll文件。我想实现使用加载项监视C ++ DLL的变量值。也就是说,当变量值发生变化时,加载项将监视此更改并响应更改。我想用事件机制来实现这个功能,但我真的遇到了麻烦。请给我一些关于这个问题的建议。谢谢!

Question BackGroud:

Recently, I develop a .Net Add-Ins application, this add-ins is loaded into VS2010 after VS2010 start.

when I open a C++ project with VS2010, i need to debug this C++ project. however, this c++ project will call a Unmanaged C++ dll file. I want to implement to monitor a variable values of the C++ dll using Add-Ins. that is to say, when the variable values change, the Add-Ins will monitor this change and respond changes. I want to implement this function with Events machanism, but I really meet trouble in this matter. pls give me some advices about this question. thanks!

Eventhandler很好。但是你需要触发本机数据类型并使用正确的接口。



以下是C#端的示例:

C#中的事件和事件处理 [ ^ ]



以及如何使用dll:

用C#隐藏窗口 [ ^ ]



我有一个项目,我可以在这个项目中使用它并且它可以正常工作多年。
Eventhandler are fine. But you need to fire native data types and work with the right interfaces.

Here is a sample on the C# side:
Events and event handling in C#[^]

and here how to consume dlls:
Window Hiding with C#[^]

I have a project in which I do this stuff and it works fine for years.


KastenK,感谢您解决我的问题。我已经根据你的想法解决了问题,它可以工作。再次感谢。
KastenK,Thanks for your solution for my question. and I have resolved the problem based on your ideas, it can work. thanks again.