HRESULT hr, hr is a long integer.
if (FAILED(hr))...
WCHAR string[20]; swprintf(string, 20, "%x", hr); MessageBox(NULL, string, NULL, MB_OK);
This should help as the first step to decode the hresult errors.
The shared bitmap is not documented that well but here is one advantage that I've found.
When you create a shared bitmap from a WIC bitmap, you can basically display the wic bitmap by using render_tgt->DrawBitmap(...) without the need to copy the pixels to the bitmap first. On a side note, the WIC bitmap and wic_lock interface allows you to address the pixels directly.
So far, I have not seen any method to work backwards and create a render target from a bitmap or shared bitmap or memory. Even the CreateBitmapFromMemory method just copies the data into a d2d bitmap and any updates to the d2d bitmap does not affect the memory it was created from. To create a shared bitmap your render target must be software type. Direct 3D does not support Direct 2D software render targets. Don't give up. There might be some guru out there that can figure out if QueryInterface will unlock some magical hidden useful features from a shared d2d bitmap.
Software Usage:
Create a WIC bitmap on the "child"
Create a D2D Render target from the WIC bitmap
Create a Shared bitmap from the main window every time you need to display the bitmap then release it immediately.
Notes: The bitmap properties must be compatible between the render targets and wic bitmap and the shared bitmap
Notes: you cannot use the wic-d2d-render-target while the wic lock or shared bitmap are active.
This way the WIC bitmap is your anchor. This would be a workaround to using shared memory.
Maintain Hardware usage:
child -> copy the bitmap bits to memory
main -> copy the memory into a bitmap created by the main window.
Either way, the bitmap properties such as bppp, order or bytes, etc.. must be compatible between render targets for the child and main window
HRESULT XMAIN::Create_HWnd_Tgt(ID2D1HwndRenderTarget **hwnd_tgt, HWND hwnd, bool makebmp)
{
if (hwnd == NULL) { return E_POINTER; }
if (hwnd_tgt == NULL) { return E_POINTER; }
if (demo.d2d.factory == NULL) { return E_FAIL; }
HRESULT hr = S_OK;
RECT rc = { 0 };
SafeRelease(hwnd_tgt);
GetClientRect(hwnd, &rc);
D2D1_RENDER_TARGET_PROPERTIES rt_props = D2D1::RenderTargetProperties();
D2D1_SIZE_U size = D2D1::SizeU((rc.right - rc.left), (rc.bottom - rc.top));
//This is required when using a wic shared bitmap
rt_props.type = D2D1_RENDER_TARGET_TYPE_SOFTWARE;
rt_props.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM;
rt_props.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE;
rt_props.dpiX = 0;
rt_props.dpiY = 0;
rt_props.usage = D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE;
rt_props.minLevel = D2D1_FEATURE_LEVEL_9;//D2D1_FEATURE_LEVEL_DEFAULT;
// Create a Direct2D render target.
hr = demo.d2d.factory->CreateHwndRenderTarget(
rt_props,
D2D1::HwndRenderTargetProperties(hwnd, size),
hwnd_tgt
);
if ((*hwnd_tgt) == NULL) {}
return hr;
}