<bdo id='0GLpM'></bdo><ul id='0GLpM'></ul>

<i id='0GLpM'><tr id='0GLpM'><dt id='0GLpM'><q id='0GLpM'><span id='0GLpM'><b id='0GLpM'><form id='0GLpM'><ins id='0GLpM'></ins><ul id='0GLpM'></ul><sub id='0GLpM'></sub></form><legend id='0GLpM'></legend><bdo id='0GLpM'><pre id='0GLpM'><center id='0GLpM'></center></pre></bdo></b><th id='0GLpM'></th></span></q></dt></tr></i><div id='0GLpM'><tfoot id='0GLpM'></tfoot><dl id='0GLpM'><fieldset id='0GLpM'></fieldset></dl></div>

<small id='0GLpM'></small><noframes id='0GLpM'>

  • <tfoot id='0GLpM'></tfoot>

        <legend id='0GLpM'><style id='0GLpM'><dir id='0GLpM'><q id='0GLpM'></q></dir></style></legend>

        C# 组件事件?

        C# component events?(C# 组件事件?)

        1. <tfoot id='Q9tmc'></tfoot>

              <tbody id='Q9tmc'></tbody>

                <bdo id='Q9tmc'></bdo><ul id='Q9tmc'></ul>
                <i id='Q9tmc'><tr id='Q9tmc'><dt id='Q9tmc'><q id='Q9tmc'><span id='Q9tmc'><b id='Q9tmc'><form id='Q9tmc'><ins id='Q9tmc'></ins><ul id='Q9tmc'></ul><sub id='Q9tmc'></sub></form><legend id='Q9tmc'></legend><bdo id='Q9tmc'><pre id='Q9tmc'><center id='Q9tmc'></center></pre></bdo></b><th id='Q9tmc'></th></span></q></dt></tr></i><div id='Q9tmc'><tfoot id='Q9tmc'></tfoot><dl id='Q9tmc'><fieldset id='Q9tmc'></fieldset></dl></div>

                <small id='Q9tmc'></small><noframes id='Q9tmc'>

                • <legend id='Q9tmc'><style id='Q9tmc'><dir id='Q9tmc'><q id='Q9tmc'></q></dir></style></legend>
                  本文介绍了C# 组件事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试编写一个公开事件的 C# 组件.该组件将由非托管 C++ 应用程序导入.根据一些教程,我想出了这段代码(用于 C# 端):

                  I am attempting to write a C# component which will expose events. The component is to be imported by an unmanaged C++ application. According to a few tutorials I have come up with this code (for the C# side):

                  namespace COMTest
                  {
                  [ComVisible(true),
                  Guid("02271CDF-BDB9-4cfe-B65B-2FA58FF1F64B"),
                  InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
                  public interface ITestEvents
                  {
                      void OnTest();
                  }
                  
                  [ComVisible(true),
                  Guid("87BA4D3A-868E-4233-A324-30035154F8A4")]
                  public interface ITest
                  {
                      void RaiseTest();
                  } // End of ITest
                  
                  [ComVisible(true),
                  Guid("410CD174-8933-4f8c-A799-8EE82AF4A9F2"),
                  ClassInterface(ClassInterfaceType.None),
                  ComSourceInterfaces(typeof(ITestEvents))]
                  public class TestImplimentation : ITest
                  {
                      public TestImplimentation()
                      {
                      }
                  
                      public void RaiseTest()
                      {
                          if (null != OnTest)
                              OnTest();
                      }
                  
                      public delegate void Test (); //No need to expose this delegate
                      public event Test OnTest;
                  }
                  }
                  

                  现在我的 c++ 代码有一个简单的:

                  Now my c++ code has a simple:

                  #import "COMTest.tlb" named_guids raw_interfaces_only
                  

                  这会生成一个 tlh 文件.此 tlh 文件包含除我的事件 (OnTest) 之外的所有内容.我做错了什么?

                  Which generates a tlh file. This tlh file contains everything but my event (OnTest). What am I doing incorrectly?

                  推荐答案

                  COM 事件接收器对于外行来说是相当邪恶的.

                  COM Event Sinks are pretty evil to the uninitiated.

                  步骤基本是

                  • 创建一个传出(源)接口
                  • 实施一个IConnectionPointContainer 和IConnectionPoint 接口,使用这些传递一个客户端实现源接口的

                  消息是,在互操作命名空间中有一些属性可以帮助您(大部分)自动执行此操作(ComSourceInterfacesAttribute) 有一个很好的使用例子这里.

                  The good news is that in the interop namespace there are attributes to help you do this (mostly) automatically (ComSourceInterfacesAttribute) There is a decent example of its usage here.

                  这篇关于C# 组件事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  How can I force the PropertyGrid to show a custom dialog for a specific property?(如何强制 PropertyGrid 显示特定属性的自定义对话框?)
                  Associate attribute with code generated property in .net(将属性与 .net 中的代码生成属性相关联)
                    <bdo id='40Bc2'></bdo><ul id='40Bc2'></ul>
                  • <i id='40Bc2'><tr id='40Bc2'><dt id='40Bc2'><q id='40Bc2'><span id='40Bc2'><b id='40Bc2'><form id='40Bc2'><ins id='40Bc2'></ins><ul id='40Bc2'></ul><sub id='40Bc2'></sub></form><legend id='40Bc2'></legend><bdo id='40Bc2'><pre id='40Bc2'><center id='40Bc2'></center></pre></bdo></b><th id='40Bc2'></th></span></q></dt></tr></i><div id='40Bc2'><tfoot id='40Bc2'></tfoot><dl id='40Bc2'><fieldset id='40Bc2'></fieldset></dl></div>
                    <tfoot id='40Bc2'></tfoot>

                        <tbody id='40Bc2'></tbody>

                    • <small id='40Bc2'></small><noframes id='40Bc2'>

                            <legend id='40Bc2'><style id='40Bc2'><dir id='40Bc2'><q id='40Bc2'></q></dir></style></legend>