Import External Memory fail

my os system is win10 x64
cuda version:v10.2.89
gpu is: GeForce GTX 1080

I want to copy a cef shared texture data and send it to another pc, just like remote desktop. First I must get the shared texture data, I use cudaImportExternalMemory function, the code below:

cudaError_t CudaD3D11Resource2BGR_A(void * shareHandle, int Size) {
if (!bInit) {
bInit = true;
unsigned char* BGRAbuffer = NULL;
cudaHostAlloc(&BGRAbuffer, Size, 0);

cudaExternalMemoryHandleDesc ExternalMemoryHandleDesc;
cudaExternalMemory_t ExternalMemory = NULL;
void *CudaDevVertptr = NULL;
cudaError_t Error = cudaSuccess;
memset(&ExternalMemoryHandleDesc, 0, sizeof(ExternalMemoryHandleDesc));

ExternalMemoryHandleDesc.type = cudaExternalMemoryHandleTypeD3D11ResourceKmt;
ExternalMemoryHandleDesc.handle.win32.handle = shareHandle;
ExternalMemoryHandleDesc.size = Size;
ExternalMemoryHandleDesc.flags = cudaExternalMemoryDedicated;
Error = cudaImportExternalMemory(&ExternalMemory, &ExternalMemoryHandleDesc);
if (Error) {
	WCHAR out[500];
	swprintf_s(out, 500, L"error:%hs\n", cudaGetErrorName(Error));
	return Error;
return cudaSuccess;


the CudaD3D11Resource2BGR_A will return error(code:999(cudaErrorUnknown)) when I invoke it like below:

ID3D11Texture2D* tex = nullptr;
auto hr = device_->OpenSharedResource(shareHandle, __uuidof(ID3D11Texture2D),
if (FAILED(hr)) {
return nullptr;


CudaD3D11Resource2BGR_A(tex, td.Width * td.Height * 4);

the shareHandle is cef(Chromium Embedded Framework) provided in
CefRefPtr browser,
CefRenderHandler::PaintElementType type,
const CefRenderHandler::RectList& dirtyRects,
void* share_handle)

I thinks the shareHandle is ok,and I can use it to render web data. I dont known what is wrong, can someone help me?