简体   繁体   中英

Debugging a Win32 application c++

My application started life as a c++ Console application in VS2019. Code was provided as part of an SDK. Worked perfect. Great response from the manufacturer USB device. Later, I wanted to graduate is to a GUI application, much as I've been doing in VB and c#. Lo and behold, I managed to reconstruct the application in both Qt and Win32 but I'm running into a situation where the application becomes unresponsive and I have no way to tell what's going on.

In the Console application, I have to execute this code to interface with the device AFTER sending a "TakeMeasurement" command:

        if (SDK_SUCCESSFUL(sdkError)) {
            printf("\nWaiting for measurement to complete...\n");
            while (!isMeasureWait) {
                if (isDisConnect) break;                        
                this_thread::sleep_for(chrono::milliseconds(1000));
            }
        }

This code works like a charm, Ater one or two iteration. the device has completed the measurement and I can get to the data easily.

On the Win32 side, I use the exact same code. Only, once control enters the loop, it never returns.

Any idea how I could diagnose the error? I have the impression that the "timing" is critical, between the exact moment where the Measurement command is initiated to the exact moment the instrument signals that it's done, and the data ready to be picked up.

My naive hypothesis is that, in debug mode on both 'platforms', I must be getting some timing differences? Sadly, I can't get more information from the manufacturer in this regard but I suspect I have a small window of time within which the instrument's response can be acted on? And I begin to suspect that, on Win32, that "time" is too long? Compared to on the Console side?

I was thinking of, perhaps, "measuring" that time, in milliseconds? First, on the Console side, to see what kind of delay "works", and then, to see how the delay compares with the Win32 side.

I may be wasting my time and I sure don't mean to waste yours.

How would I go about getting an idea of time elapsed in a c++ application? I'll take a look around VS2019, they have all kinds of "performance" things that popup at run time?

Any help is appreciated.

I am not sure I completely understand what is going on. Execution of the thread wait loop was not not the culprit. I'm not 100% sure but what happens is that, in my 'Export data to CSV TEXT file', if I tried to execute the call to:

SetWindowText(hEditMeasure, wMeasurements);

The application always hung. I placed breakpoints right before the call in the code, to trace execution, and it did not strike me at first but, in VS toolbar, there was a "thread" comboBox? With the value showing = DEVICE.DLL? and to its right, the name of my Export function as the Stackframe. In searching for additional information on the setWindowText function, I came accross the reference to use VM_SETTEXT to send to "different application"? Could it be unknowingly I was sending a message to "another thread", the DLL thread? And that's why it hung? I did not know enough to tell. So I started to move the setWindowText line around, ultimately inside the code that is called by the "Measure" button, and it worked!

I'm not out of the woods yet but I feel I'm making progress. Thank you all for your help and patience.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM