You must read the documentation of this functions carefully in
GetPhysicalMonitorsFromHMONITOR is written that it is real device but the
QueryDisplayConfig is about all possible devices. So the functions are different and you should not merge the code to careless and get fooled by the same variable names. Best is to rename and keep both code pathes and carefully study and debug the usage.
I guess that one code is for enumerate all possible resolutions and the other has the output of the actual settings.