如何将聚合 .NET COM Interop 添加到 ATL EXE 服务器?
我想知道如何将 .NET C# COM 对象(使用 .NET 的 COM Interop 工具创建)添加到 Visual Studio 2008 ATL EXE 服务器。基本上,我试图创建一个进程外自动化服务器来保存我的 C# COM 对象,以允许它充当许多客户端的单例服务器。我想我需要做的就是将正确的条目添加到 ATL EXE 服务器的 IDL 文件中?这听起来正确吗?那么有人知道如何实际实例化我的 C# COM 对象吗?我猜我需要重新定义它的 GUID,否则它会立即实例化 C# 的 GUID?感谢您的任何帮助。
- 以大卫
为例: 。
import "oaidl.idl";
import "ocidl.idl";
[
uuid(A9F9E81F-D5FE-4718-8078-E8378CFB3D3C),
version(1.0),
helpstring("Libreria dei tipi SSOLoginDLLServer 1.0")
]
library SSOLoginDLLServerLib
{
importlib("stdole2.tlb");
import "SSOLoginDLL.tlb"; <-- Reference included to my C# project which creates the TLB
[
uuid(A8FD5BC5-3B8D-4828-B9CB-6496A7A6D9B9)
]
coclass CSSOLogin
{
[default] interface ISSOLogin;
[default, source] dispinterface ISSOLoginEvents;
};
};
I would like to know how one can add a .NET C# COM object (created using the COM Interop facility of .NET) to a Visual Studio 2008 ATL EXE Server. Basically, I am trying to create an out of process Automation server to hold my C# COM object to allow it to act as a Singleton server for many clients. I think all I need to do is add the proper entries to the ATL EXE Server's IDL file? Does this sound right? Would anybody also have any idea how to actually instantiate my C# COM object then? I am guessing I need to redefine its GUID otherwise it would just instantiate the C# one right away? Thanks for any help.
-David
For Example:
.
import "oaidl.idl";
import "ocidl.idl";
[
uuid(A9F9E81F-D5FE-4718-8078-E8378CFB3D3C),
version(1.0),
helpstring("Libreria dei tipi SSOLoginDLLServer 1.0")
]
library SSOLoginDLLServerLib
{
importlib("stdole2.tlb");
import "SSOLoginDLL.tlb"; <-- Reference included to my C# project which creates the TLB
[
uuid(A8FD5BC5-3B8D-4828-B9CB-6496A7A6D9B9)
]
coclass CSSOLogin
{
[default] interface ISSOLogin;
[default, source] dispinterface ISSOLoginEvents;
};
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,您有一个 COM 对象(您的 ATL 服务器),其存在的唯一目的是让客户端能够访问另一个 COM 对象(C# 对象)。需要注意的是,您并不是在谈论让客户端访问 TYPE(即它们将实例化自己的 C# 对象实例),而是让客户端访问实际的 INSTANCE。
因此,您的 ATL 服务器需要定义并实现一个提供必要访问的接口。您可以只返回 C# 对象:
在这种情况下,客户端还需要了解 C# 库中的所有类型定义,以便他们在获取该对象后可以使用该对象。
或者你可以包装它,这样客户端只需要了解你的主要类型库:
无论哪种方式,我认为这就是你在问“[我会]需要重新定义其 GUID”时的意思吗——是的,类型由 ATL 服务器定义的(及其 GUID)需要独立于它们碰巧使用的其他类。
(顺便说一句,抱歉我没有给你正确的 IDL 或任何东西......自 1999 年以来我还没有真正创建过 COM 对象。)
So you have one COM object (your ATL server), which exists for the sole purpose of giving clients access to another COM object (the C# object). It's important to note that you're not talking about giving clients access to the TYPE (i.e. they will instantiate their own instance of the C# object) but rather to the actual INSTANCE.
So your ATL server needs to define and implement an interface that provides the necessary access. You could either just return the C# object:
in which case the client will also need to know all the type definitions from the C# library, so that they can work with this object once they get it.
or you could wrap it, so that clients only need to know about your primary type library:
Either way, I think this is what you mean when you are asking '[would I] need to redefine its GUID' -- yes, the types (and their GUIDs) defined by your ATL server need to be independent distinct from the other classes they happen to use.
(BTW, sorry I'm not giving you correct IDL or anything here ... I haven't actually created a COM object since 1999.)