加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

.net – 在Win7中使用没有注册表的COM Exe Server

发布时间:2020-12-14 01:56:58 所属栏目:Windows 来源:网络整理
导读:我有一个现有的COM Exe Server,以及调用它的VBA或.NET代码.我们希望无需安装或修改注册表即可使其工作,以便其计算机上不是管理员的其他用户可以使用它. 我们假设无法更改/修改COM Exe Server(昂贵). 问题1: 根据我在Registering a Running EXE Server中所做
我有一个现有的COM Exe Server,以及调用它的VBA或.NET代码.我们希望无需安装或修改注册表即可使其工作,以便其计算机上不是管理员的其他用户可以使用它.

我们假设无法更改/修改COM Exe Server(昂贵).

问题1:
根据我在Registering a Running EXE Server中所做的,EXE服务器可以调用CoRegisterClassObject在类表中注册CLSID.这是否意味着客户端应该能够从那里获得CoGetClassObject? (甚至没有该类型/类的注册表项?)

问题2:
如果以上是正确的,我的EXE服务器使用CComModule(不建议使用,是),我可以看到确实在调用CoRegisterClassObject.有没有办法验证类表,所以看到是否正确完成?

问题3:
这是我正在使用的片段. clsid和iid指的是相应的clsid和iid guids.它在CreateInstance调用中未注册接口(HRESULT异常:0x80040155)失败.这让我感到难过,任何可能出错的想法?

var factory = UnsafeNativeMethods.CoGetClassObject(
            clsid,RegistrationClassContext.LocalServer,IntPtr.Zero,typeof(UnsafeNativeMethods.IClassFactory).GUID)
                      as UnsafeNativeMethods.IClassFactory;

            factory.CreateInstance(null,ref iid,out obj);

解决方法

Question 1: From what I undertand in Registering a Running EXE Server,
the EXE server can call CoRegisterClassObject to register the CLSID in
the class table. Does that mean clients should be able to
CoGetClassObject from there? (even w/o registry entries for that
type/class?)

是. CoRegisterClassObject就足够了(没有注册表),可以让任何使用CLSCTX_LOCAL_SERVER调用CoCreateInstance的客户端可以使用out-of-proc对象.但是,您可能遇到编组调用问题,因为未注册COM代理/存根DLL和/或类型库.因此,IDispatch,IOleCommandTarget等众所周知的接口将被编组而不会出现问题,但任何自定义接口都将失败.

但是,还有其他方法可以让客户端使用EXE服务器.仅举几例:RegisterActiveObject,IRunningObjectTable.

Question 2: If the above is correct,my EXE Server uses CComModule
(deprecated,yes) and I can see is is indeed calling
CoRegisterClassObject. Is there a way to verify the class table so see
that is is done correctly?

我只能想到调用CoGetClassObject或CoCreateInstance(需要CLSCTX_LOCAL_SERVER标志)来验证.

Question 3: This is the snippet I am using. clsid and iid refer to the
coresponding clsid and iid guids. It fails with Interface not
registered (Exception from HRESULT: 0x80040155) in the call to
CreateInstance. This makes me sad,any idea on what might be wrong?

那真是怪了.如果COM标准编组程序找不到接口的代理/存根工厂,则它将返回0x80040155(REGDB_E_IIDNOTREG),但IClassFactory不需要自定义代理.您确定IClassFactory的C#定义中有正确的GUID吗?那应该是Guid(“00000001-0000-0000-C000-000000000046”).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读