# opencl interop with directx9

**URL:** <https://forums.developer.nvidia.com/t/opencl-interop-with-directx9/19921>\
**Category:** CUDA Programming and Performance\
**Created:** [November 24, 2010, 5:44am UTC](https://forums.developer.nvidia.com/t/opencl-interop-with-directx9/19921 "2010-11-24T05:44:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nvlover](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@nvlover](https://forums.developer.nvidia.com/u/nvlover)\
**Post date:** [November 24, 2010, 5:44am UTC](https://forums.developer.nvidia.com/t/opencl-interop-with-directx9/19921/1 "2010-11-24T05:44:54Z")

</div>

```auto
IDirect3D9* d3d =NULL;

   d3d = Direct3DCreate9(D3D_SDK_VERSION);  

   if (d3d == NULL)  

   {  

      //error handle

   }  

   //set Direct3D presentation parameters  

   D3DPRESENT_PARAMETERS d3dp;   

   ZeroMemory(&d3dp, sizeof(d3dp));  

   d3dp.Windowed = TRUE;  

   d3dp.SwapEffect = D3DSWAPEFFECT_DISCARD;  

   d3dp.BackBufferFormat = D3DFMT_UNKNOWN;  

   //create Direct3D device  

   IDirect3DDevice9* pDevice =NULL;

   HRESULT hr =d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,  

      D3DCREATE_SOFTWARE_VERTEXPROCESSING,  

      &d3dp, &pDevice );   

   if (pDevice == NULL)  

   {  

      //error handle

   }   

clGetDeviceIDsFromD3D9NV_fn clGetDeviceIDsFromD3D9NV =

   (clGetDeviceIDsFromD3D9NV_fn)clGetExtensionFunctionAddress("clGetDeviceIDsFromD3D9NV");

   if (clGetDeviceIDsFromD3D9NV==NULL) 

   {

      //error handle

   }

   cl_uint uNum(0);

   err =clGetDeviceIDsFromD3D9NV(gid, CL_D3D9_DEVICE_NV, pDevice, CL_PREFERRED_DEVICES_FOR_D3D9_NV, 1, &g_Device, &uNum);

```

I use code above, but when I invoke clGetDeviceIDsFromD3D9NV, I got the return value -1. what`s wrong?

thank you.

---

<div class="post-metadata">

**Author:** ![nvlover](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@nvlover](https://forums.developer.nvidia.com/u/nvlover)\
**Post date:** [November 24, 2010, 5:44am UTC](https://forums.developer.nvidia.com/t/opencl-interop-with-directx9/19921/2 "2010-11-24T05:44:54Z")

</div>

```auto
IDirect3D9* d3d =NULL;

   d3d = Direct3DCreate9(D3D_SDK_VERSION);  

   if (d3d == NULL)  

   {  

      //error handle

   }  

   //set Direct3D presentation parameters  

   D3DPRESENT_PARAMETERS d3dp;   

   ZeroMemory(&d3dp, sizeof(d3dp));  

   d3dp.Windowed = TRUE;  

   d3dp.SwapEffect = D3DSWAPEFFECT_DISCARD;  

   d3dp.BackBufferFormat = D3DFMT_UNKNOWN;  

   //create Direct3D device  

   IDirect3DDevice9* pDevice =NULL;

   HRESULT hr =d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,  

      D3DCREATE_SOFTWARE_VERTEXPROCESSING,  

      &d3dp, &pDevice );   

   if (pDevice == NULL)  

   {  

      //error handle

   }   

clGetDeviceIDsFromD3D9NV_fn clGetDeviceIDsFromD3D9NV =

   (clGetDeviceIDsFromD3D9NV_fn)clGetExtensionFunctionAddress("clGetDeviceIDsFromD3D9NV");

   if (clGetDeviceIDsFromD3D9NV==NULL) 

   {

      //error handle

   }

   cl_uint uNum(0);

   err =clGetDeviceIDsFromD3D9NV(gid, CL_D3D9_DEVICE_NV, pDevice, CL_PREFERRED_DEVICES_FOR_D3D9_NV, 1, &g_Device, &uNum);

```

I use code above, but when I invoke clGetDeviceIDsFromD3D9NV, I got the return value -1. what`s wrong?

thank you.
