使用COM埃克服务器W / O注册表在Win7 [英] Using COM Exe Server w/o Registry in Win7

查看:292
本文介绍了使用COM埃克服务器W / O注册表在Win7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的COM埃克服务器,VBA或.NET code调用它。我们希望,使工作W / O型无需安装或修改注册表,以便使不上他们的机器管理员的其他用户可以使用它。

让我们假设改变/修改COM的Exe服务器是不可能的(昂贵的)。

问题1: 从我undertand在注册运行EXE服务器,EXE文件服务器可以调用CoRegisterClassObject注册CLSID在类表中。这是否意味着客户应该能够从那里CoGetClassObject? (甚至W / O为该类型/类的注册表项?)

问2: 如果以上是正确的,我的EXE服务器使用的CComModule(德precated,是的),我能看到的是确实调用CoRegisterClassObject。有没有一种方法来验证类表,看是正确完成?

问题3:
这是我使用的代码片段。 CLSID和IID指coresponding CLSID和IID的GUID。它失败的接口未注册(从HRESULT异常:0x80040155)的中调用CreateInstance。这让我难过,什么可能是错的?任何想法

  VAR厂= UnsafeNativeMethods.CoGetClassObject(
            CLSID,
            RegistrationClassContext.LocalServer,
            IntPtr.Zero,
            typeof运算(UnsafeNativeMethods.IClassFactory).GUID)
                      作为UnsafeNativeMethods.IClassFactory;

            factory.CreateInstance(空,参考独立同分布,出OBJ);
 

解决方案
  

问题1:从我undertand在登记正在运行的EXE服务器,   EXE文件服务器可以调用CoRegisterClassObject注册CLSID中   类表。这是否意味着客户应该能够   CoGetClassObject从那里? (甚至W / O该注册表项   类型/班?)

是的。 CoRegisterClassObject 就足够了(没有注册表)进行外进程内的你的对象提供给该调用的任何客户端的CoCreateInstance CLSCTX_LOCAL_SERVER 。但是,您可能有问题,封送话费,因为COM代理/存根DLL和/或类型库没有注册。因此,像一个众所周知的接口的IDispatch IOleCommandTarget 等没有问题会被封,但任何自定义的接口将失败

有其他的方法可以让你的EXE服务器提供给客户,但。仅举几例: RegisterActiveObject ,的 IRunningObjectTable

  

问题2:如果上面是正确的,我的EXE服务器使用的CComModule   (德precated,是的),我能看到的是确实呼唤   CoRegisterClassObject。有没有一种方法来验证类表等等看   即正确完成?

我只能想到调用的 CoGetClassObject 的CoCreateInstance (或者需要 CLSCTX_LOCAL_SERVER 标记)来验证。

  

问题3:这是我使用的代码片段。的clsid和IID指   coresponding CLSID和IID的GUID。它失败,接口不   注册(从HRESULT异常:0x80040155)在调用   的CreateInstance。这让我难过,什么可能是错的?任何想法

这是奇怪。在COM标准的封送返回0x80040155(REGDB_E_IIDNOTREG),如果它不能找到一个代理/存根工厂的接口,但的IClassFactory 不需要自定义代理。你确定你有一个正确的的GUID 的IClassFactory 你的C#的定义是什么?这应该是的Guid(00000001-0000-0000-C000-000000000046)

I have an existing COM Exe Server, and VBA or .NET code calling it. We'd like to make it work w/o needing to install or modify the registry so that other users that are not admins on their machines can use it.

Let's assume changing/modifying the COM Exe Server is not possible (expensive).

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?)

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?

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?

            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?)

Yes. CoRegisterClassObject will be enough (without registry) to make your out-of-proc object available to any client which calls CoCreateInstance with CLSCTX_LOCAL_SERVER. However, you may have problems with marshaling calls, because the COM proxy/stub DLL and/or type library are not registered. So, a well-know interfaces like IDispatch, IOleCommandTarget etc will be marshaled without problems, but any custom interfaces will fail.

There are other ways to make you EXE server available to the clients, though. To name a few: 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?

I can only think of calling CoGetClassObject or CoCreateInstance (either needs CLSCTX_LOCAL_SERVER flag) to verify that.

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?

That's weird. The COM standard marshaler returns 0x80040155 (REGDB_E_IIDNOTREG) if it can't find a proxy/stub factory for an interface, but IClassFactory doesn't require a custom proxy. Are you sure you have a correct GUID in your C# definition of IClassFactory? That should be Guid("00000001-0000-0000-C000-000000000046").

这篇关于使用COM埃克服务器W / O注册表在Win7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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