我有一个现有的 COM Exe 服务器和调用它的 VBA 或 .NET 代码。我们想让它在不需要安装或修改注册表的情况下工作,以便其他不是他们机器上的管理员的用户也可以使用它。
让我们假设更改/修改 COM Exe 服务器是不可能的(代价高昂)。
问题 1: 据我了解 Registering a Running EXE Server ,EXE服务器可以调用CoRegisterClassObject在类表中注册CLSID。这是否意味着客户应该能够从那里获取 CoGetClassObject? (甚至没有该类型/类别的注册表项?)
问题 2: 如果以上是正确的,我的 EXE 服务器使用 CComModule(已弃用,是的)并且我可以看到它确实在调用 CoRegisterClassObject。有没有一种方法可以验证类表以确保是否正确完成?
问题三:
这是我正在使用的片段。 clsid 和 iid 指的是相应的 clsid 和 iid guid。它在对 CreateInstance 的调用中失败,接口(interface)未注册(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
的客户端。但是,您可能会遇到编码(marshal)处理调用的问题,因为 COM 代理/ stub DLL 和/或类型库未注册。因此,IDispatch
、IOleCommandTarget
等众所周知的接口(interface)将毫无问题地编码,但任何自定义接口(interface)都会失败。
不过,还有其他方法可以让您的 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 标准编码器找不到接口(interface)的代理/ stub 工厂,则返回 0x80040155 (REGDB_E_IIDNOTREG),但 IClassFactory
不需要自定义代理。您确定在 IClassFactory
的 C# 定义中有正确的 GUID
吗?那应该是 Guid("00000001-0000-0000-C000-000000000046")
。
关于.net - 在 Win7 中使用不带注册表的 COM Exe 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21897466/