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

<legend id='sNz17'><style id='sNz17'><dir id='sNz17'><q id='sNz17'></q></dir></style></legend>

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

      1. 如何在 C# 中枚举 COM 对象的成员?

        时间:2023-07-26
        <legend id='DMlTA'><style id='DMlTA'><dir id='DMlTA'><q id='DMlTA'></q></dir></style></legend>
      2. <tfoot id='DMlTA'></tfoot>
              <tbody id='DMlTA'></tbody>

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

                • <bdo id='DMlTA'></bdo><ul id='DMlTA'></ul>

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

                  本文介绍了如何在 C# 中枚举 COM 对象的成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我通过 COM 连接到某个程序并接收 System.__ComObject.我知道它的几种方法,所以我可以这样做:

                  I connect to some program via COM and receive System.__ComObject. I know several methods of it, so I can do like this:

                  object result = obj.GetType().InvokeMember("SomeMethod", BindingFlags.InvokeMethod, null, obj, new object[] { "Some string" });
                  

                  像这样

                  dynamic dyn = obj;
                  dyn.SomeMethod("Some string");
                  

                  这两种方法都可以正常工作.但是如何确定 com 对象的内部类型信息并枚举其所有成员?

                  Both methods works fine. But how can I determine inner type information of com object and enumerate through all its members?

                  我试过了:

                  [ComImport, Guid("00020400-0000-0000-C000-000000000046"),
                    InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
                  public interface IDispatch
                  {
                    void Reserved();
                    [PreserveSig]
                    int GetTypeInfo(uint nInfo, int lcid, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(TypeToTypeInfoMarshaler))] out System.Type typeInfo);
                  }
                  
                  ...
                  
                  IDispatch disp = (IDispatch)obj;
                  Type t;
                  disp.GetTypeInfo(0, 0, out t);
                  

                  但 t 最后为空.谁能帮帮我?

                  But the t is null at the end. Can anyone help me?

                  推荐答案

                  您无法获取 COM 对象的类型.这将需要您为 COM 组件创建一个互操作库.如果 COM 服务器有一个类型库,这肯定是一个低痛点,只需添加对它的引用或运行 Tlbimp.exe 实用程序.如果存在,则类型库通常嵌入在 DLL 中.当你得到它时,编辑器和对象浏览器都会对 COM 类上可用的方法和属性变得更加智能.

                  You cannot get a Type for the COM object. That would require you creating an interop library for the COM component. Which is certainly the low pain point if the COM server has a type library, just add a reference to it or run the Tlbimp.exe utility. If it is present then the type library is usually embedded inside the DLL. When you got that, both the editor and the Object Browser get a lot smarter about the method and properties available on the COM class.

                  看到 IDispatch 转换工作,很可能还有一个类型库可用.COM 服务器作者创建一个非常简单.另一个可以用来查看类型库的工具是 OleView.exe,View + Typelib.

                  Seeing the IDispatch cast work makes it quite likely that a type library is available as well. It is pretty trivial for the COM server author to create one. Another tool you can use to peek at the type library is OleView.exe, View + Typelib.

                  如果这不起作用,那么您确实可以从 IDispatch 中挖掘东西.您的声明看起来很可疑,IDispatch::GetTypeInfo 的第三个参数是 ITypeInfo,一个 COM 接口.无需自定义编组器,ITypeInfo 在 System.Runtime.InteropServices.ComTypes 命名空间中可用.您可以使用 Reflector 从框架代码中挖掘 IDispatch 声明.

                  If that doesn't work then you can indeed dig stuff out of IDispatch. Your declaration looks fishy, the 3rd argument for IDispatch::GetTypeInfo is ITypeInfo, a COM interface. No need for a custom marshaller, ITypeInfo is available in the System.Runtime.InteropServices.ComTypes namespace. You can dig the IDispatch declaration out of the framework code with Reflector.

                  当然,体面的文档是无可替代的.当您获得使用此组件的许可证时,您应该能够获得一些.

                  And of course, there's no substitute for decent documentation. You should be able to get some when you got a license to use this component.

                  这篇关于如何在 C# 中枚举 COM 对象的成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:用自定义 VBA 类包装 .Net ArrayList 获取迭代器 下一篇:使用 IFileOperation 在复制期间创建目录

                  相关文章

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

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

                        <bdo id='S3Yen'></bdo><ul id='S3Yen'></ul>
                    1. <tfoot id='S3Yen'></tfoot>