如何在.NET中MSAdminBase COM对象的工作? [英] How to work with the MSAdminBase COM object in .NET?

查看:331
本文介绍了如何在.NET中MSAdminBase COM对象的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个对象在%WINDIR实现%\ SYSTEM32 \将Admwprox.dll - 看看 HKEY_CLASSES_ROOT \ CLSID \ {70B51430-B6CA-11D0-B9B9-00A0C922E750}

This object is implemented in %windir%\system32\ADMWPROX.DLL - see HKEY_CLASSES_ROOT\CLSID\{70B51430-B6CA-11D0-B9B9-00A0C922E750}

这是从C code非常有用的,但我想它与.NET code和什么是无赖更换 - 将Admwprox.dll不会显示为一个有效的类型库TLBIMP:

It is perfectly usable from C code, but I wish to replace it with a .NET code and what a bummer - ADMWPROX.DLL does not appear as a valid type library to tlbimp:

z:\Work>tlbimp c:\Windows\system32\admwprox.dll
Microsoft (R) .NET Framework Type Library to Assembly Converter 4.0.30319.1
Copyright (C) Microsoft Corporation.  All rights reserved.

TlbImp : error TI1002 : The input file 'c:\Windows\system32\admwprox.dll' is not a valid type library.

z:\Work>

当然,它是从COM对象的列表中添加在Visual Studio COM引用时丢失。

And of course, it is missing from the list of COM objects when adding a COM reference in Visual Studio.

请,帮助。

P.S。

我想设定 IIS://本地主机/ W3SVC / 1将SSLCertHash 财产的这篇文章解释说,只有这样,才能做到这一点是通过 MSAdminBase 的对象,而不是 MSAdminObject (由于在架构定义中的错误)。后者是由.NET System.DirectoryServices.DirectoryEntry 方便的包装,但前者不 - ,因此是我的痛

I am trying to set the IIS://localhost/W3SVC/1!SslCertHash property and this article explains that the only way to do it is through the MSAdminBase object, rather than MSAdminObject (due to a bug in the schema definition). The latter is conveniently wrapped by the .NET System.DirectoryServices.DirectoryEntry, but the former is not - hence is my pain.

推荐答案

确定,这里就是我是如何做的:

OK, here is how I did it:

  1. 改装IMSAdminBase_W接口定义IDL。该接口是从微软的SDK iadmw.h声明。它包含了所有在注释中的IDL属性,因此转换是很容易。当然,IDL需要声明组件类和图书馆也是如此。
  2. 然后我编译IDL文件使用MIDL。
  3. 接下来,我跑TLBIMP上产生的TLB文件。
  4. 最后,所产生的互操作的dll已被固定,特别TLBIMP归因结构与StructLayout.Pack = 4,其将失败我们,如果在.NET作为64比特运行 - 见<一href="http://stackoverflow.com/questions/6712481/access-violation-inside-inetinfo-exe-when-passing-byte-array-through-imsadminbase">Access从编译值为anycpu 一个.NET应用程序通过IMSAdminBase字节数组时,违规内部inetinfo.exe的。我用Reflector.NET进行反编译它。事实上,我然后只包含在反编译互操作性源作为我的项目的一部分。
  1. Converted the IMSAdminBase_W interface definition to IDL. The interface is declared in iadmw.h from the Microsoft SDK. It contains all the IDL attributes inside comments, so the conversion is easy. Of course, the IDL needs to declare the coclass and the library as well.
  2. Then I compiled the IDL file with midl.
  3. Next, I ran tlbimp on the resulting tlb file.
  4. Finally, the produced interop dll had to be fixed, specifically TlbImp attributed the structures with the StructLayout.Pack = 4, which will fail us if the .NET runs as 64 bits - see Access Violation inside inetinfo.exe when passing byte array through IMSAdminBase from a .NET app compiled to AnyCPU. I used Reflector.NET to decompile it. In fact, I then just included the decompiled interop source as part of my project.

就是这样。

我没有创建互操作的源$ C ​​$ c作为第一个也是唯一的一步,因为在IMSAdminBase_W接口是相当大的,所以我preferred将其转换为IDL,这是比较容易。

I did not create the interop source code as the first and only step, because the IMSAdminBase_W interface is quite large, so I preferred to convert it to IDL, which was easier.

这篇关于如何在.NET中MSAdminBase COM对象的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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