Guidance:
Recently, I am working on a small project. Because the intermediate algorithms are complicated and messy, I want to output a monitoring value where I need it, to monitor the execution of the intermediate algorithm, I first thought of breakpoint debugging, but every time the program is continuously interrupted, it is very inconvenient. I tried trace, but it must also be done in debug debugging mode, which is very painful. Even one day, let's look at Sir's in-depth introduction to MFC. In the appendix, we provided a detailed explanation of the reconstruction of dbwin with MFC, which was suddenly ecstatic and carefully studied, which provided many methods, however, I still like the dbwin tool, God, which is really saving me. The dbwin program has already been provided to us and can be easily obtained in msdn, this is done by the famous Paul dilascia and you don't have to worry about its functions. But every time you use this tool, you must modify the source code, which is really troublesome, pay attention to the location where the initialization program is called. I felt a little uncomfortable. I took a look at the requested header file and the initialization program to be called, I was wondering if I could add a debug program by myself. Initialization must be called first, right, to construct a global object, so I wrote a class myself, place the initialization program in the constructor of the global object. The source program is as follows:
// Mytrace. h
# Ifndef _ mytrace_h __
# DEFINE _ mytrace_h __
# Ifdef _ debug
# Include
Class mytrace
{
Public:
Mytrace ()
{
: Mfxtraceinit ();
}
~ Mytrace (){}
};
Mytrace _ mytrace;
# Endif // _ debug
# Endif/_ myrtace_h __
Put this file and
These two files are stored in the default include directory. If you want to use dbwin, you only need to put mytrace. h. This file is included in your program. It is best to include it in the file that builds theapp to monitor all the processes that your program wants to monitor. Wow, it is indeed much more convenient. Open the dbwin window. The trace string you added is clearly displayed in the monitoring window. You don't even need to open the VC environment and run the debug program you generated, in this way, if you want to debug several programs at the same time, such as communication between programs, it is very convenient and enjoyable to see.
However, it is still a little troublesome to include a header file every time. Can I embed this file into the header file of afxwin? Because the header file must be included to write the MFC program, hurry up and try again. No. An error occurs. It seems that the definition is repeated. However, this header file has already been pre-compiled to ensure that repeated definitions are not displayed, check the relevant information about this connection error. It seems that it is caused by some VC relationships, but it still cannot be solved after a long time. I will post this article to ask you about the connection error, maybe you have a better method for trace. I hope you can give me some advice and have a better solution to the errors I 've encountered. Thank you very much. Here's my mail, dyroro@163.com
This article is transferred from
Http://blog.113e.com/237898.shtml