IDXGIResource::GetSharedHandle Method

Gets the handle to a shared resource.

Note

Starting with Direct3D 11.1, we recommend not to use GetSharedHandle anymore to retrieve the handle to a shared resource. Instead, use IDXGIResource1::CreateSharedHandle to get a handle for sharing. To use IDXGIResource1::CreateSharedHandle, you must create the resource as shared and specify that it uses NT handles (that is, you set the [D3D11RESOURCE_MISC_SHARED_NTHANDLE](D3D11_RESOURCE_MISC_FLAG_typedef__d3d11_X_M_T.htm) flag). We also recommend that you create shared resources that use NT handles so you can use CloseHandle, DuplicateHandle, and so on on those shared resources.

Syntax

public:
HRESULT GetSharedHandle(
         HANDLE *pSharedHandle
)  

Parameters

pSharedHandle
Type: HANDLE *

[out] A pointer to a handle.

Return value

Type: HRESULT 

Returns one of the DXGI_ERROR values.

Remarks

GetSharedHandle returns a handle for the resource that you created as shared (that is, you set the [D3D11RESOURCE_MISC_SHARED](D3D11_RESOURCE_MISC_FLAG_typedef__d3d11_X_M_T.htm) with or without the [D3D11RESOURCE_MISC_SHARED_KEYEDMUTEX](D3D11_RESOURCE_MISC_FLAG_typedef__d3d11_X_M_T.htm) flag). You can pass this handle to the ID3D11Device::OpenSharedResource method to give another device access to the shared resource. You can also marshal this handle to another process to share a resource with a device in another process. However, this handle is not an NT handle. Therefore, don’t use the handle with CloseHandle, DuplicateHandle, and so on.

The creator of a shared resource must not destroy the resource until all intended entities have opened the resource. The validity of the handle is tied to the lifetime of the underlying video memory. If no resource objects exist on any devices that refer to this resource, the handle is no longer valid. To extend the lifetime of the handle and video memory, you must open the shared resource on a device.

GetSharedHandle can also return handles for resources that were passed into ID3D11Device::OpenSharedResource to open those resources.

GetSharedHandle fails if the resource to which it wants to get a handle is not shared.

Requirements

Header: Declared in d3d11_x.h (dxgi.h on other Windows platforms).

Library: Use d3d11_x.lib (dxgi.lib on other Windows platforms).

See also

IDXGIResource

IDXGIResource Members