在不同进程之间共享HDC [英] Sharing HDC between different processes

查看:131
本文介绍了在不同进程之间共享HDC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写某种IPC功能,需要将某些资源从一个进程传递到另一个进程.这对于可以通过DuplicateHandle复制的Pipe句柄等效果很好.现在,我需要将HDC从一个进程传递到另一个进程.这有可能吗?如果是,怎么办?

I am writing some kind of IPC functionality and need to pass certain resources from one process to another. This works well for Pipe handles etc. which can be duplicated via DuplicateHandle. Now I need to pass a HDC from one process to the other. Is this even possible? If yes: how?

子问题:我假设将窗口句柄(HWND)从一个进程传递到另一个进程是安全的.这个假设正确吗?

Sub-Question: I am assuming passing window handles (HWND) from one process to the other is safe. Is this assumption correct?

推荐答案

所有GDI句柄都存储在映射到每个进程的表中.该表中的条目包含拥有进程的进程ID,并且在每次对该句柄的GDI访问中都会对其进行检查.

All GDI handles are stored in a table that is mapped into every process. The entries in the table contain the process id of the owning process, and this is checked on every GDI access to the handle.

因此,(具有讽刺意味的),GDI句柄-包括HDC-在整个系统范围内都是有效的.但是只能在创建它们的过程中使用.

So, (ironically), GDI handles - including HDCs - are valid system wide. But can only be used from the process that created them.

此页面记录了GDI对象.当然,需要指出的是,值得注意的是,一些COM功能以及诸如WM_PRINT之类的窗口消息没有进程间限制,并且它们通过了HDC,因此它们显然必须在幕后做一些事情才能将HDC从一个进程中封送.到下一个.

This Page documents the process affinity of GDI objects. Of course, as a counter point it is worth noting that some COM functions, and window messages like WM_PRINT do not have any interprocess restrictions and they ARE passed HDC's, so they clearly have to do something behind the scenes to marshal the HDC from one process to the next.

这篇关于在不同进程之间共享HDC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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