|I state up front that I am not experienced with GUIs. My tasks include VS MFS dialogs to control how the app runs and show its performance, but the app is a number cruncher and has no significant user interface. Once started there is no user interaction. The problem is probably a beginner's error so do not hesitate to ask or point out the basics.
This test app is an MFC dialog and has only one dialog. I don't know your intent in differentiating between "dialog or main window." It is only a few steps beyond a just created MFC dialog project.
So far in the test project there is one edit box, one check box, and one button. A right click on the edit box produced a drop down and "Add variable" was selected. The name used was m_box_get_port_number. I added the check for status per your code and it is returned with value 0, false. The error code remains 1421.
The one button has the event handler shown in the OP and runs that code.
Is all that of any use?
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com