Hi Rob,
I use the following code to create the device and context,
Microsoft::WRL::ComPtr<ISurfaceImageSourceNative> nativeImgSrc;
UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1
};
ComPtr<ID3D11Device> device;
ComPtr<ID3D11DeviceContext> context;
D3D_FEATURE_LEVEL m_featureLevel;
ComPtr<IDXGIDevice> dxgiDevice;
D3D11CreateDevice(
null,
D3D_DRIVER_TYPE_HARDWARE,
0,
creationFlags,
featureLevels,
ARRAYSIZE(featureLevels),
D3D11_SDK_VERSION,
&device,
&m_featureLevel,
&context
);
device.As(&dxgiDevice);
this->nativeImgSrc->SetDevice(dxgiDevice.Get());
ComPtr<ID2D1Device> d2dDevice;
D2D1CreateDevice(dxgiDevice.Get(), NULL, &d2dDevice);
d2dDevice->CreateDeviceContext( D2D1_DEVICE_CONTEXT_OPTIONS_NONE, &this->d2dContext);
While debugging, I found that the following call to BeginDraw returns E_FAIL result,
ComPtr<IDXGISurface> surface;
HRESULT hResult = this->nativeImgSrc->BeginDraw(rect, &surface, &offset);
and subsequently, System.AccessViolationException occurs at the following call,
d2dContext->CreateBitmapFromDxgiSurface(surface.Get(), NULL, &bitmap);
I think IDXGISurface is not created.
Thanks,