how to log in win32 c++ to the visual studio output window? - winapi

My log4net is logging to the visual studio output windows but what code can I use in the C++ win32 code to do the same as I need to debug the C++ and can't seem to step through it at all and logging would be useful in production as well anyways. I added
wprintf(L"Registering hook handler\n");
but that doesn't seem to work. It has been years since I have done C++ as well, let alone win32 C++.

I think you're looking for OutputDebugString().

Related

Custom Visual Studio Debug Engine for Simulator

I have a requirement for developing a debugger extension for Visual Studio. The code is in C++, however, it is run in a simulator environment. The application is capable of receiving break points and displaying variable information.
I have looked into the Concord API, but it seems rather complex. Do I have to develop an Expression Evaluator, even though the code is in C++?
Basically I just want the program to run and hit the breakpoints that the user has created for starters.
Should I try and write a visual studio extension instead? Although I don't see any way of halting execution of a program in debug mode?
Thanks
Ah the joy of writing a custom debugger! I'm writing one now. See the visual studio custom debug engine sample to start with. Python Tools for Visual Studio, MIDebugEngine are more complex but also more complete and production code. Much easier to write the debugger in C#.
Some blogs that helped me a lot.
https://limbioliong.wordpress.com/2011/08/30/creating-a-com-server-using-c/
https://blogs.msdn.microsoft.com/jmstall/2009/07/09/icustomqueryinterface-and-clr-v4/
VS2005 SDK PDF has more detailed debugger documentation.
VS2015/17 C# Extension projects has a custom project type package which comes with a script debugger launcher to start with.

Debugging C++ with Visual Studio debugger

I want to write an extension for Visual Studio Code (VSCode) which will allow me to debug a C++ program with Visual Studio's native C++ debugger instead of gdb (which currently is the only option VSCode supports). I looked at the Visual Studio Debugger Extensibility. But it only explains how you can create a new debug engine and call it from Visual Studio as a front end. What I want to do is the opposite. I want to call the existing Visual Studio C++ debug engine from a different front end, which happens to be VSCode. There is no documentation on the Internet how I can achieve this. Can anyone please help?
I'm on the VSCode team. To use the VS debugger from VSCode, you will need to author a debug adapter extension. Here's some documentation on getting started, and here's the complete debug adapter protocol reference.
Try look at some existing implementations to get started:
Mock debugger – simple example debugger
Node debugger - node.js debug adapter
For C++, also check out C++ tools for VSCode.
Hope that helps.
Edit - Seems I misunderstood the problem. Here are some thoughts on consuming the VS C++ debugger from an external application.
To my knowledge, Visual C++ does not have public APIs or interfaces that allows external programs to easily interface with them. Other languages have better stories, since they often leverage external libraries or were designed with documented debugger protocols. The GDB machine interface is a good example of this sort of design.
My best suggestion is that you could try to leverage the Visual Studio Env.DTE interfaces to control VS programmatically. EnvDTE is not well documented and may not be exactly what you are after, but it is pretty powerful.

Debugging tool for managed code

I am new to C# and wondering whether "windbg" or "Visual Studio Debugger" would be better tool for debugging managed code?
For the past couple of years, I have been doing development in C++ and I am comfortable in using windbg as compared to Visual Studio debugger. However, I am not sure whether windbg would work best in the case of managed code as well?
Is there any other debugging tool besides windbg and Visual Studio Debugger which works even better than these in debugging managed code?
WinDbg needs SOS or PSSCOR2/4 to debug managed code, but with either of those you get a very powerful debugger. However, I would not recommend using only WinDbg for managed code as support for source debugging is rather limited at the moment (and has been for a long time). You might also want to get SOSEX as it complements SOS/PSSCOR with additional useful commands.
In my experience Visual Studio works very well for regular debugging and WinDbg+SOS/PSSCOR2 is excellent for all those hairy problems such as memory issues, deadlocks and so forth that VS doesn't handle very well.

How to Debug Windows Service written in VC++ in VS2008?

HI,
How to Debug Windows Service written in VC++ in VS2008 ?
Any help is appreciated.
You can use:
DebugBreak() to break your code whereever you want.
or
Debug Flags utility that comes as a part of Windbg Installer to break as soon as a particular process starts.
I've previously written up a number of debugging tips for Windows services in C++ here: Convert a C++ program to a Windows service?

How to build workspace from DDK examples?

I am new to win32 programming and also to driver programming. I have installed Windows DDK on my system and have got some examples with the DDK but those examples don't have dsw file.
I wanted to know how can I create .dsw file so that I can open that workspace in VC6.
Most people who build DDK/WDK projects in Visual Studio do so using a 'makefile' project that invokes the DDK's build.exe utility. This works quite well- you get the code navigation capabilities of Visual Studio while building your DDK project using the standard, supported DDK tools.
Note that the DDK comes with it's own set of compilers, and those compilers should be used to build DDK projects.
OSR has a little set of cmd scripts that is supposed to make this easier (it's been years since I've done anything with those; I really can't remember how well they work):
http://www.osronline.com/article.cfm?article=43
Another similar tool is available from Hollis Technology:
http://www.hollistech.com/Resources/ddkbuild/ddkbuild.htm
As far as debugging goes, unfortuantely the VS debugger won't work for kernel mode driver debugging. For that, get the Debugging Tools for Windows package which has a great set of debuggers. The GUI debugger, WinDbg, is quite nice even if it's not quite up to the usability of Visual Studio's. And the documentation with the Debugging Tools is outstanding - you can learn a lot about Windows internals just by reading the WinDbg docs.
The last time I looked (which was years ago), you don't build device drivers using the Visual Studio IDE: the DDK has its own build.exe utility (similar idea but not the same as makefiles); and apparently this is still true as of early 2008, see for http://groups.google.com/group/microsoft.public.development.device.drivers/browse_thread/thread/4382c9b66f8611e9?pli=1
I expect that "how to build" is described in the DDK documentation.
I think better you integrate with Visual Studio 2005, 2008 or 2010 with this tool:
http://visualddk.sysprogs.org/versions/1.5.6
ChrisW is correct, you can't use Visual Studio (unless there is a way to set it).
Anyway, for start debugging you can use DebugView to print simple messages with DbgPrint.
VC6 is very old these days, can't you use a newer version? Anyway, as I recall, you can just open the project file as a workspace, the IDE will create the .dsw file for you.

Resources