Gold mine of Visual C++ tricks!
How to locate the source code which pops the error message – More easily.
![]()
While debugging huge code bases, unexpectedly some error messages can be popped up. Most probably we might be seeing it for the first time and don’t have any idea, from which location of the code base, the error message get fired. How to locate it easily?
![]()
Just follow the steps -
1) Start the project by F5.
2) Do the steps to make the error messagebox to be shown. Now the error message will be shown.
3) Now instead of clicking of in the error message, take debugger and click menu, Debug -> Break.
4) Now take Debug -> Threads to see the threads running in your application.
5) You can see one of your thread, which is paused in a messagebox showing routine.
6) Select that thread and click SetFocus, to focus that thread.
7) Now take the Call Stack by Alt+7 and iterate through it from top to bottom.
8 ) You see one familiar function? Yes! its the one which pops the error message. Now go and fix the bug
![]()
You can also put a breakpoint by finding the memory address of the functions that can be used for showing error messages. But, if the application uses some custom dialogs, then you’ve to put more effort. This method is the handy one with least headaches. Try it!
![]()
Targeted Audience – Beginners.
| Print article | This entry was posted by Jijo Raj on April 17, 2008 at 4:08 pm, and is filed under Codeproject, Debugging Tips. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
No trackbacks yet.
How to check whether the thread is alive or dead?
about 6 months ago - 3 comments
In multi-threaded environments, sometimes we need to check whether a given thread is alive or not. But how can we check it?
Picture courtesy – Erica Marshall
You can use the function – GetExitCodeThread(). If thread is alive, the function returns STILL_ACTIVE. Have a look at the code snippet.
// Checks whether given thread is alive.
bool IsThreadAlive(const HANDLE
How to set Focus to Different Control on Dialog Startup?
about 6 months ago - 1 comment
Do you want to set the focus to another control on displaying Dialog? Or tried SetFocus() to another control in OnInitDialog() and want to know why its not working? The answer for your ‘Focus’ question is here.
If you are setting the default focus to another control in dialog, then OnInitDialog() should return FALSE. Have a
How to Get Project Build Time?
about 6 months ago - No comments
Many times i lost my temper by waiting for the re-build to be finished. So i just attempted to tune and reduce the build time by removing unnecessary includes. At that time I just wondered how to get the build time?
Just follow the steps to enable the ‘Build Time’.
1) Take – Tools > Options.
2) Now
Search for Symbols in Visual Studio more Easily
about 9 months ago - 2 comments
Ever tried VisualAssist? Yes man, Its a killer product. The feature that I like most is its Symbol Search. You can specify words and it will list symbols that contain those words. Its very useful if you have a vague idea about the function name that you’re searching for. Have a look at the following
C++ Function Pointers Simplified!
about 10 months ago - 2 comments
Background information
Pointer is a variable which holds the address of another variable. Where, function pointer is again a variable which holds the address of a function.
If you think pointers are evil, then function pointers must be Satan for you. Well, is there any easy way to create function pointers from function prototype?
How to Set Dialog as TopMost Window?
about 10 months ago - No comments
I always wondered about popularity of Winamp. It has rich custom drawn UI, which made it stand out of the crowd. Did you noticed its “Always on top” feature and wondered about how its implemented? Its time to reveal the secret – How winamp implemented that feature – Staying at the top?
You can use –
How to Watch this Pointer – The Wizards Way!
about 1 year ago - 6 comments
How to watch the this pointer? Just add ‘this’ to watch window. Everyone does like that. Isn’t it? But how Visual C++ wizards watch ‘this’ pointer?
The secret is, visual C++ compiler passes this pointer via ECX register. So add (ClassName*)(@ECX) to watch window will give you this pointer. Have a look at the
How to get the CPU Name String?
about 1 year ago - 3 comments
While taking the System properties, you have noticed the processor name string. For instance, in my laptop it is – “Intel(R) Core(TM)2 Duo CPU T5250 @ 1.50GHz“. Ever though about how to get this processor name string?
Image Courtesy – Wallpaper Mania.
You can use the function – __cpuid(), which generates the
How to Change the Display Orientation?
about 1 year ago - 4 comments
Are you using Windows XP? Press Ctrl+Atl+DownArrow, and then Ctrl+Atl+UpArrow. The screen changes its orientation upside down. isn’t it? But how to turn the screen, upside down programmatically?
Image Courtesy – marieforleo.com
Get the current DEVMODE by calling -EnumDisplaySettings(). Then change orientation by setting DEVMODE.dmDisplayOrientation and calling ChangeDisplaySettings(). Have a look at the code snippet. Code taken
How to Delete Duplicate entries from STL containers?
about 1 year ago - 4 comments
If you want to remove duplicate items, you can go for stl::set. But what to do if you want to delete duplicate data from other containers?
Picture Courtesy – Squidoo
You can use std::unique() algorithm to remove adjacent duplicate items. So at first, sort your data, then call std::unique(). Now all the duplicate data will be rearranged
about 2 years ago
its a good idea when working with a single threaded application. But If the application have multiple threads, there is no gurantee that the thread the break point is hit on the thread the showed the message box. So i think its better to find the techique to switch thread and then checking the call stack.
about 2 years ago
My goodness. I forgot to say about switching threads! Actually i prepared the steps by executing a HelloWorld app.