Hello Goukenfan,
I have not had much exposure to Windows C++ for quite a while but I'll try to help. Just to be clear, the problem you are facing is that line 29 in code above fails i.e.
Code:
hr = factory->CreateSwapChainForHwnd(
device,
m_amahwnd,
&desc,
NULL,
NULL,
&swapchain
);
My first instinct would be to confirm that the factory pointer is not NULL. The next thing I would ask would be about the arguments you are passing into the CreateSwapChainForHwnd method. If in doubt, read the documentation
IDXGIFactory2::CreateSwapChainForHwnd (dxgi1_2.h) - Win32 apps | Microsoft Docs