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?
Related
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.
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().
The situation might sound a bit weird but I have to play with what I have.
There's a Win2003 64-bit server OS and a legacy application written using Visual Studio 6. The app consists of two parts: ActiveX components written in VB6 and C++ code which uses them.
I need to debug the components' code. I installed Visual Studio 6 on the server and I'm able to step into the component's code. Then I got following situation:
C++ code works until it needs to instantiate component A.
We switch to VB6 and start debugging component's A VB6 code.
In the very beginning component A creates an instance of a class C exposed by component B. At this step VB6 debugger shows error message with title "OLEDB32.DLL" and following text:
"Failed to load resource DLL C:\Program Files (x86)\Common Files\System\Ole DB\OLEDB32R.DLL"
Additional information: The last step in initialization of the class C is opening an ADO connection to SQL server using OLEDB provider.
I'd appreciate any ideas on how resolve this problem.
Thanks in advance.
The VB6 debugger has a reputation for sometimes being a bit flaky, and I'm not sure it was ever supported on 64-bit operating systems.
There are some other options for debugging VB6.
You could try debugging the VB6 in the Visual C++ 6 debugger at the same time as the C++. Compile the VB6 into native code with symbols (create PDB files). Then you should be able to step from the C++ straight into the VB6 and still debug. I have done this before (not on 64-bit). Here's a Microsoft knowledgebase article on doing this with C++ 5 - I think it's much the same in C++ 6. Here's info on doing it with Visual C++ 2008 (!)
Or you could try running the program in Windbg, a free standalone debugger from Microsoft. Again compile your VB6 into native code with symbols (PDB files) and you will be able to debug your VB6 in Windbg. You should also be able to debug the C++ at the same time.
Here's a 2006 blog post by a Microsoft guy about using Windbg with VB6, and 2004 blog post by another Microsoft VB guy with a brief introduction to Windbg.
MDAC registers ADO/OLEDB classes like this: %CommonProgramFiles%\System\Ole DB\sqloledb.dll
Check if your process environment is corrupted in some way. If you use restart manager (when your app crashes it is restarted) does not restore environment. We guard with something like this in Sub Main
If LenB(Environ$("CommonProgramFiles")) = 0 Then
Call SetEnvironmentVariable("CommonProgramFiles", pvGetSpecialFolder(ucsOdtProgramFilesCommon))
End If
If LenB(Environ$("CommonProgramFiles(x86)")) = 0 Then
Call SetEnvironmentVariable("CommonProgramFiles(x86)", pvGetSpecialFolder(ucsOdtProgramFilesCommon))
End If
Surely the answer will be "you can't" or "use XP mode", but I'd like to know if it it possible.
The issue I have is that whenever I debug some application and hit a breakpoint, when I stop the debugger the debuggee remains stuck. It can't be killed, I can't attach another debugger (it says it is already being debugged). It won't go away until I close Visual C++.
This is hapenning on a Windows 7 64 bits install. VC has SP 6 installed.
My previous fix was horrible.
Finally, I developped a new fix, working perfectly with the english version of Visual Studio 6. (SP6 I think)
You need to check the version of the file DM.dll located into "Common/MSDev98/Bin"
The correct version is 6.0.9782.0.
link: http://www.dr-hoiby.com/TLLOC.dll (28KB)
how to install: replace "Common/MSDev98/Bin/TLLOC.dll" by the version downloaded.
Best regards.
Comment reposted:
You can try using Visual Studio 2008 with VC6 compiler. I recently blogged about this.
I developped a little fix for that.
You just have to copy the file "ShiftF5Fix.dll" into "Common/MSDev98/AddIns/" et load it from Visual.
It's an hugly fix.
If you modify your source file during debugging you have you answer "NO" to the poup displayed after you press "SHIFT+F5" to stop the process.
link : http://www.dr-hoiby.com/ShiftF5Fix.dll
Best regards
Another option would be to install daffodil.
This is an open source project to compile all versions of visual studio in VS2010.
Once this is configured you can use visual studio 2010 debugger to debug VC6 projects.
On the heels of Dr Holby, I implemented a leaner variant, with source code:
http://www.algonet.se/~tamlin/TLLOC_fixer.zip
The code currently only understands sp4 (?) and SP6, but I think it'll cover most cases.
You only need to compile the source (1.cpp, 1.rc), rename your existing TLLOC.DLL (which btw stands for Transport Layer Local - as opposed to remote debugging) to TLLOC.old.dll, and drop in the one you compiled (~4KB). Should work like a charm for all 32-bit debugging needs, from Windows 95 to Windows 7 (and later).
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.