如何将DirectX共享资源的句柄传递给另一个(不相关的)进程? [英] How do I pass a handle of DirectX shared resource to another (unrelated) process?

查看:124
本文介绍了如何将DirectX共享资源的句柄传递给另一个(不相关的)进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在两个不相关的进程(无子进程)之间传递 HANDLE



HANDLE rSharedHandle 来自 DXDevice9-> CreateTexture(w,h,1,0,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,& pTexture9,& rSharedHandle);



我想/需要在另一侧使用它,通过 DXDevice11-> OpenSharedResource( rSharedHandle,__ uuidof(ID3D11Resource),(void **)(& TmpResource11));



该过程的完整说明可以是在此处找到。 / p>



我遇到了这个问题,可以作为答案,但不够清楚,我无法理解它们的意思。 在此处查看



我还遇到了 marshal_as ,这在此处,但我不了解如何在我的情况下使用它。有关采用的类型的更多详细信息,可以找到这里





编辑(1):
我不想处理如果可能,托管代码。因此,我搜索了更多有关如何在进程之间传递/共享句柄的信息。我遇到过函数 DuplicateHandle()请参阅此处),但由于句柄的类型无效(请参阅备注部分中的列表),或者是否



此外,第二个进程句柄需要在DuplicateHandle()(在函数本身中使用)之前发送,然后将结果复制句柄需要发送到第二个进程(最终使用)。

解决方案

我发现了一种简单(粗略)的方法去做吧。比最终产品更多的是工作量的证明,但它确实有效!



我的操作方式如下:


  1. 在第一个过程中从纹理创建 rSharedHandle (叫作P1)

  2. 我将对应于句柄的8个字节写入二进制文件

  3. 在P2中,我读取了同一文件并设置了 rSharedHandle (在P2中)

看上去似乎很容易,但效果很好。



如果您想要/需要更多详细信息,请随时在评论中提问。


I'm trying to pass a HANDLE between two unrelated processes (no child process).

This HANDLE rSharedHandle comes from DXDevice9->CreateTexture(w, h, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &pTexture9, &rSharedHandle);

And I want / need to use it on the other side to be shared using DXDevice11->OpenSharedResource(rSharedHandle, __uuidof(ID3D11Resource), (void**)(&TmpResource11));

The complete explanation of the procedure is can be found here.


I came across this question which as answers but not clear enough that I understand what they mean. See this here.

I also came across the marshal_as which is explained here, but I don't understand how to use it in my case. Further details about the types taken can be found here.


EDIT (1): I don't want to deal with managed code if possible. So I search more about "How to pass/share handle between processes". I came across the function DuplicateHandle() (See here) but I cannot find whether it doesn't work because the type of the handle is not a valid type (See list in Remarks section), or whether it is because of something else (unknown).

Moreover, the second process handle needs to be send before DuplicateHandle() (to be used in the function itself) and the resulting duplicated handle needs to be send to the second process (to finally be used).

解决方案

I found a simple (and gross) way to do it. It is more a proof of work than a final product but it is working!

The way I proceed was the following:

  1. Create the rSharedHandle from the texture in the first process (lets call it P1)
  2. I write to a binary file the 8 bytes corresponding to the handle
  3. In P2, I read the same file and set the rSharedHandle (in P2)

And as easy as it seems, it works well.

Feel free to ask questions in the comment if you want/need more details.

这篇关于如何将DirectX共享资源的句柄传递给另一个(不相关的)进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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