Problen while creating ID2D1RenderTerget
See the question and my original answer on StackOverflowAs I said in my comment, your must declare renderTarget as ID2D1HwndRenderTarget* because the CreateHwndRenderTarget method expects this type, so just change your test code declaration like this for example:
void test(ID2D1Factory* factory, ID2D1HwndRenderTarget* rendertarget, HWND hwnd)