什么是($ Foo)PS项目在我的$ Foo ATL解决方案? [英] What is the ($Foo)PS project in my $Foo ATL solution for?

查看:194
本文介绍了什么是($ Foo)PS项目在我的$ Foo ATL解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MSVC中创建一个ATL项目似乎只创建了两个项目;后者命名与前者相同,但附加了PS的名称。

Creating an ATL project in MSVC seems to create not one but two projects; the latter named the same as the former but with PS appended to its name. What is the purpose of this second project and how can I tell whether I need it?

推荐答案

COM支持跨接口方法调用两个不同的线程,两个不同的进程或两个不同的机器。这称为 marshaling 。两个不同的线程是最常见的情况,一个COM服务器往往不是线程安全的。 COM通过将从错误的线程调用到创建服务器的线程来实现这种单线程coclass的线程安全。当您编写一个进程外服务器时,进程之间进行封送。在网络中的不同机器之间被称为DCOM。

COM supports making interface method calls across two different threads, two different processes or two different machines. This is called marshaling. Two different threads is the most common case, a COM server is often not thread-safe. COM implements thread-safety for such single-threaded coclasses by marshaling the call from the 'wrong' thread to the thread that created the server. Marshaling between processes occurs when you write an out-of-process server. Between different machines across a network is called DCOM.

这是通过创建一个像原来那样看起来像的接口实例来实现的。但是接口的所有方法实际上是做调度调用的工作的替代。这是代理。在线的另一端有一个替代,看起来像完全像接口,但做相反的工作。这是存根。

This is implemented by creating an instance of the interface that looks exactly like the original. But all the methods of the interface are actually substitutes that do the job of the marshaling the call. This is the proxy. On the other end of the wire there's a substitute that looks exactly like the interface but does the opposite job. This is the stub. The proxy and stub work together to create the illusion that you're making a simple method call in your program.

代理的主要工作是将参数序列化该方法调用进入内存缓冲区或网络包。这可能是很不重要的,特别是当你使用指针到可变大小的结构。 COM需要帮助,以获得正确的,这是你的FooPS项目的工作。当您在.idl文件上运行midl.exe时,midl会从接口定义自动生成代码,以实现代理和存根。这通常足够好,但如果midl中的内置关键字不足以描述您的数据,您可能需要实现自己的。

The primary job of the proxy is to serialize the arguments of the method call into a memory buffer or network packet. This can be pretty untrivial, especially when you use pointers to variable-sized structures. COM needs help to get that right and that's the job of your FooPS project. When you run midl.exe on your .idl file, midl auto-generates code from the interface definitions to implement the proxy and the stub. This is quite often good enough but you may need to implement your own if the built-in keywords in midl are not sufficient to describe your data.

最后但并非最不重要的, Windows提供了一个标准的编组器,可以编组简单的接口。设计用于支持COM Automation定义的COM子集。换句话说,从IDispatch派生并且只使用自动化兼容类型的接口。类似于ATL向导生成的接口。您只需要获得注册表项正确启用它,否则不需要由midl生成的代理/存根。当然,如果你只在一个线程上进行简单的进程内调用,那么你也不需要它。这是很常见的。

Last but not least, Windows provides a standard marshaller that can marshal simple interfaces. Designed to support the sub-set of COM that's defined by COM Automation. In other words, interfaces that derive from IDispatch and only use Automation compatible types. Like the interfaces that the ATL wizards generate. You only need to get the registry entries right to enable it and don't otherwise need the proxy/stub generated by midl. And of course, if you only make simple in-process calls on one thread then you won't need it either. This is pretty common.

这篇关于什么是($ Foo)PS项目在我的$ Foo ATL解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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