使用Com Interop从VB到C ++的事件处理 [英] Event handling from VB to C++ with Com Interop

查看:72
本文介绍了使用Com Interop从VB到C ++的事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



自从我尝试从VB发起事件并用C ++捕获它们的日子 - 很遗憾没有任何成功。我的理由是:我不是VB开发人员,也不知道这里使用的所有机制。



为了您更好的理解,这是我目前的情况和我取得的成就远:



我想在我的MFC / C ++应用程序中使用许可的.NET Dll,但不能使用/ clr选项进行编译。所以我需要托管.NET世界和非托管C ++之间的包装器。



我的第一次尝试是使用C ++ / Cli。最后,我有一个原则上可以调用.NET Dll的lib,但是每次因为我无法通过lib传递.NET Dll许可证密钥时我都收到了许可证。



之后,.NET Dll的支持团队转发了一个链接到VB包装器,该链接器能够与.NET Dll通信并作为COM对象工作。所以我编译了这个VB Wrapper并在我的C ++应用程序中导入了生成的dll / tlb。现在我可以通过VB Wrapper调用.NET Dll的函数了。



但是因为我需要对来自.NET Dll的事件做出反应我也尝试过使用VB Wrapper捕获事件和/或将它们转发到我的C ++应用程序。在这种情况下,我不知道如何捕获/触发事件。我已经阅读了很多如何,但没有一个能帮助我。有人谈到了连接点和回调,但我无法想象如何设置它 - 无论是在VB还是在C ++上。



我希望你们中的一些人有一个相当的这个简单的例子展示了如何在VB COM对象中触发事件以及如何在C ++客户端中捕获它。

Hello,

since days I try to fire events from VB and catch them with C++ - unfortunately w/o any success. To my excuse: I am not a VB developer and do not know all the mechanisms used here.

For your better understanding here is my current situation and what I achieved so far:

I want to use a licensed .NET Dll in my MFC/C++ application but cannot use the /clr option for compiling. So I need a wrapper between the managed .NET world and the unmanaged C++.

My first attempt was with C++/Cli. In the end I had a lib that was in principle able to call the .NET Dll but i received every time a License Exception since I could not pass the .NET Dll license key via the lib.

After that the support team of the .NET Dll forwarded a link to an VB Wrapper that is able to communicate with the .NET Dll and works as a COM Object. So I compiled this VB Wrapper and imported the generated dll/tlb in my C++ application. Now I am able to call functions of the .NET Dll via the VB Wrapper.

But since I need to react on events from the .NET Dll as well I tried to catch events withing the VB Wrapper and/or forward them to my C++ application. I have no idea how to catch/fire events in this scenario. I read already a lot of "how to"s but none of them helped me out. There were talked about Connection Points and Callbacks but I cannot imagine how to set this up - neither in VB nor on C++.

I hope some of you guys have a quite simple example that shows how to fire an event within a VB COM Object and how to catch it in a C++ client.

推荐答案

你应该转发你的回调函数和一些参数直到C ++应用程序并通过 PostThreadMessage 进行消息传递



最好是因为它通过将消息打包在消息队列中而是非阻塞的。
You should forward your callback function and some parameters up to the C++ App and do messaging via PostThreadMessage

It is best because it is non-blocking by packing the message in the message queue.


这篇关于使用Com Interop从VB到C ++的事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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