编组编组接口是否会为我提供代理或原始接口的编组器?
这是一个具体的示例:
我通过调用 wb 创建一个 IWeBrowser2 界面.CoCreateInstance(CLSID_InternetExplorer, 0, CLSCTX_SERVER);
.这为我提供了一个从我的进程到恰好在我的线程 A 中包含此浏览器选项卡的正在运行的 iexplore.exe 进程的编组接口。
现在我使用 IGlobalInterfaceTable 获取此接口的 cookie,将其传递给我的线程 B 并从那里请求封送接口。
问题:我是获取到线程A中的代理的代理还是直接获取到IE进程中的实例的代理?
对我来说,我将获得实例的直接代理及其自己的引用,这似乎是明智的,
但是:
如果我结束线程 A,我在那里创建的 cookie 将变得无效,并且我无法检索(并关闭)指向我创建的 Web 浏览器的界面指针。除非该线程中有一个 thunk,并且该 thunk 在线程退出时被销毁,否则这是没有意义的。
编辑:哦,两个线程都是 STA。
Here is a concrete example:
I create a IWeBrowser2 interface by calling wb.CoCreateInstance(CLSID_InternetExplorer, 0, CLSCTX_SERVER);
. This gives me a marshaled interface from my process into whichever of the running iexplore.exe processes happens to contain this browser tab in my thread A.
Now I use the IGlobalInterfaceTable to get a cookie for this interface, pass it to my thread B and request the marshaled interface from there.
Question: Do I get a proxy to the proxy in my thread A or directly to the instance in the IE process?
It seems sensible to me that I will get a direct proxy to the instance with its own reference to it,
however:
If I end my thread A, the cookie I created there becomes invalid and I can't retrieve (and close) the interface pointers to the web browsers I created any more. This does not make sense unless there is a thunk in that thread that is destroyed when the thread quits.
Edit: Oh, both threads are STA.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我终于有时间弄清楚发生了什么,所以我写了一个简短的测试来看看发生了什么。
底线是这样的:
这意味着我获得了 IE 进程的代理,而不是其他线程的对象。
I finally had some time to figure out what is happening, so I wrote a short test to see what is going on.
The bottom line is this:
This means that I get a proxy to the IE process instead of to the other thread's object.
自从您请求进程外服务器以来,您已经在线程 A 上获得了代理。接下来发生的情况取决于线程 A 所在的单元类型,即 CoInitializeEx() 的参数。如果是 MTA,假设它也是 MTA,那么您肯定会在线程 B 中获得相同的代理。如果线程 A 退出,添加的引用计数应使其保持活动状态。如果是 STA 那么我不是 100% 确定,但我认为你应该买一个新的。顺便说一句,测试很容易,只需使用线程 A 中的线程,如果必须创建一个新线程,您将得到 RPC_E_WRONGTHREAD。
我没有很好的解释为什么线程 A 退出会杀死线程 B 的代理。除非你调用 IGlobalInterfaceTable::RevokeInterfaceFromGlobal()。你通常会这样做。
You already got a proxy on thread A since you asked for an out-of-process server. What happens next depends on the kind of apartment that thread A lives in, the argument to CoInitializeEx(). If it is MTA you will definitely get the same proxy in thread B, assuming it is MTA as well. The added reference count should keep it alive if Thread A exits. If it is STA then I'm not 100% sure but think you ought to get a new one. Easy to test btw, just use the one from thread A and you'll get RPC_E_WRONGTHREAD if a new one would have to be created.
I don't have a great explanation for why the thread A exit kills the proxy for thread B. Unless you call IGlobalInterfaceTable::RevokeInterfaceFromGlobal(). Which you'd normally do.