Home   Notes   Contact Me

Visual Studio

Gotchas!

Gotchas

Local

External

Other


Making Release builds be Debug

Sections in project configuration to change
Configurations C/C++ General Debug Information Database Program Database Optimation ...

Keyboard Shortcuts

DescriptionKey(s)Details
Add New ItemControl-Shift-A
Add referenceAlt-Shift-F10
Code files, cycle through, with popup listControl-Tab
Full ScreenAlt-Shift-Enter
Goto Document Edit PanelESC
Scroll Text up 1 lineControl-Down
Alt-Shift-EnterFull Screen Toggle

Gotchas

Visual Studio Locks up in HttpSendRequest

This happens due to a problem with getting debug symbols. To get around the problem, turn off automatic loading of symbols. You can do this by going to Tools | Options... | Debugging | Symbols and checking the box Search the above locations only when symbols are loaded manually. You may be able to disable it more completely, but I like to be able to get symbols, and this allows me to still get them when I need to. NOTE: there is some obscure env variable that can ? override this ?, it is _NT_SYMBOL_PATH, make sure it is not set either. I guess this problem happens due to the symbol lookup and HttpSendRequest trying to do something with wininet.dll at the same time.


DebugBreak()

DebugBreak() in c++ can be replaced with:

_asm int 3;

Debug Symbols

Visual Studio 2005

  1. Goto To Tools | Options | Debugging | Symbols
  2. Add the 'directory' http://msdl.microsoft.com/download/symbols
  3. Make sure the symbol cache directory is set to whereever you feel like putting it.

Intellisense for custom XML files

http://www.radsoftware.com.au/articles/intellisensewebconfig.aspx


Debug Heap

0xfdNo Mans LandBuffer values around both sides of an allocated block
0xddFreed blocks
0xcdNew blocks

Good info was found at http://www.nobugs.org/developer/win32/debug_crt_heap.html

Address Offset After HeapAlloc() After malloc() During free() After HeapFree() Comments
0x00320FD8 -40 0x01090009 0x01090009 0x01090009 0x0109005A Win32 heap info
0x00320FDC -36 0x01090009 0x00180700 0x01090009 0x00180400 Win32 heap info
0x00320FE0 -32 0xBAADF00D 0x00320798 0xDDDDDDDD 0x00320448 Ptr to next CRT heap block (allocated earlier in time)
0x00320FE4 -28 0xBAADF00D 0x00000000 0xDDDDDDDD 0x00320448 Ptr to prev CRT heap block (allocated later in time)
0x00320FE8 -24 0xBAADF00D 0x00000000 0xDDDDDDDD 0xFEEEFEEE Filename of malloc() call
0x00320FEC -20 0xBAADF00D 0x00000000 0xDDDDDDDD 0xFEEEFEEE Line number of malloc() call
0x00320FF0 -16 0xBAADF00D 0x00000008 0xDDDDDDDD 0xFEEEFEEE Number of bytes to malloc()
0x00320FF4 -12 0xBAADF00D 0x00000001 0xDDDDDDDD 0xFEEEFEEE Type (0=Freed, 1=Normal, 2=CRT use, etc)
0x00320FF8 -8 0xBAADF00D 0x00000031 0xDDDDDDDD 0xFEEEFEEE Request #, increases from 0
0x00320FFC -4 0xBAADF00D 0xFDFDFDFD 0xDDDDDDDD 0xFEEEFEEE No mans land
0x00321000 +0 0xBAADF00D 0xCDCDCDCD 0xDDDDDDDD 0xFEEEFEEE The 8 bytes you wanted
0x00321004 +4 0xBAADF00D 0xCDCDCDCD 0xDDDDDDDD 0xFEEEFEEE The 8 bytes you wanted
0x00321008 +8 0xBAADF00D 0xFDFDFDFD 0xDDDDDDDD 0xFEEEFEEE No mans land
0x0032100C +12 0xBAADF00D 0xBAADF00D 0xDDDDDDDD 0xFEEEFEEE Win32 heap allocations are rounded up to 16 bytes
0x00321010 +16 0xABABABAB 0xABABABAB 0xABABABAB 0xFEEEFEEE Win32 heap bookkeeping
0x00321014 +20 0xABABABAB 0xABABABAB 0xABABABAB 0xFEEEFEEE Win32 heap bookkeeping
0x00321018 +24 0x00000010 0x00000010 0x00000010 0xFEEEFEEE Win32 heap bookkeeping
0x0032101C +28 0x00000000 0x00000000 0x00000000 0xFEEEFEEE Win32 heap bookkeeping
0x00321020 +32 0x00090051 0x00090051 0x00090051 0xFEEEFEEE Win32 heap bookkeeping
0x00321024 +36 0xFEEE0400 0xFEEE0400 0xFEEE0400 0xFEEEFEEE Win32 heap bookkeeping
0x00321028 +40 0x00320400 0x00320400 0x00320400 0xFEEEFEEE Win32 heap bookkeeping
0x0032102C +44 0x00320400 0x00320400 0x00320400 0xFEEEFEEE Win32 heap bookkeeping

Command Line

Visual Studio 6

SET VS6="C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin\MSDEV.EXE"
%VS6% test.dsw /MAKE all /OUT log.txt

// Visual Studio .NET (aka: Visual Studio .NET 2003)
// background building
devenv.exe MySolution.sln /build DEBUG
// foreground building
devenv MySolution.sln /build DEBUG
// alternate foreground building
devenv.com MySolution.sln /build DEBUG

Unit test gotcha

Unit testing in some cases copies the executable to another directory before running it. There is a way to flag other files in the project so they get copied as well if they are needed at runtime.

Here is more detailed information on this, the page is titled "More VSTS Unit Testing learnings" http://www.agileprogrammer.com/oneagilecoder/archive/2005/06/30/5281.aspx


Precompiled Headers, turning them on in a project that doesn't use them

  1. Add #include "stdafx.h" to the top of each .cpp file. An example cygwin bash script can be seen HERE
  2. Add a file named stdafx.h to your project and add the headers you want to have precompiled into it.
  3. Add a file named stdafx.cpp to your project and put this one line in it:
    #include "stdafx.h"
  4. Get to the Property dialog of your project Solution Explorer pane | context menu | Properties and do the following:
    1. Choose the Configuration: of All Configurations
    2. set C/C++ | Precompiled Headers | Create/Use Precompiled Header to Use Precompiled Header (/Yu)
    3. With the Property dialog still open, in Solution Explorer select the file stdafx.cpp
    4. Back in the Property dialog set
      C/C++ | Precompiled Headers | Create/User Precompiled Header to Create Precompiled Header (/Yc)
    5. Close the Property dialog
  5. Clean your project
  6. Build your project

Example cygwin bash script to add #include "stdafx.h"

Note: Run this from a !! SUBDIRECTORY !! of where the .cpp files you want to convert are.

#!/usr/bin/bash.exe

files=`(cd ..; ls *.cpp)`

#echo $files

for ITEM in $files
do
        echo $ITEM

        echo "#include \"stdafx.h\"" > "$ITEM.u"
        cat "../$ITEM" >> "$ITEM.u"

        u2d < "$ITEM.u" > "$ITEM"

        rm "$ITEM.u"
done

Filename Extensions

ExtensionDeletablePurpose
.apsyesBinary version of a Resource file.
Generated by the resource editor.
.idbyesVisual Studio minimum rebuild dependancy file
.ilkyesVisual Studio incremental linker file
.ncbyesVisual Studio intellisense database
.pchyesVisual Studio precompiled header file
.pdbyesVisual Studio "Program debug database"

Debugging info

What's New in the Visual Studio 2005 Debugger http://msdn2.microsoft.com/en-us/library/01xdt7cs

Debugging a crash with that doesn't show any useful stack information

I used this to find a problem in a dll that was unloaded at the time IE was calling it, during IE shutdown (I was working on an ActiveX project).


Open any file quickly in Visual Studio

Use the toolbar control for find in file, type in a command like this: >open {filename} and yes you must type the >


Windowed to Consoled, converting a project

Window'dConsole'd
C/C++ : General : Preprocessor definitions_WINDOWS_CONSOLE
Link options is box at bottom/subsystem:windows/subsystem:console

Source Control

Howto Remove Annoying Source Control Message

  1. Edit the solution file
  2. Delete the Section GlobalSection(SourceCodeControl)

Link Warnings and Errors

WarningInformation
LNK2005 Example:

Solution: Make sure the correct libraries are being used. In the case shown, I was using Multi-Threaded(/MT) in the test program and using Multi-Threaded DLL (/MD) in the libraries it was using.
Find the setting here:
Solution Explorer | Properties | C/C++ | Code Generation | Runtime Library
LNK4098 Example: default 'LIBC' conflicts with use of other libs
Solution: Add to the Additional Options text field options like this /NODEFAULTLIB:libc.lib  look here for what to actually add
Find the setting here:
Solution Explorer | Properties | Linker | Command Line

LINK 4096 settings to cut and paste

Projects ModeLibraries to ignore with /NODEFAULTLIB:
Single-threaded (libc.lib)libcmt.lib, msvcrt.lib, libcd.lib, libcmtd.lib, msvcrtd.lib
Multithreaded (libcmt.lib)libc.lib, msvcrt.lib, libcd.lib, libcmtd.lib, msvcrtd.lib
Multithreaded using DLL (msvcrt.lib)/NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrtd.lib
Debug Single-threaded (libcd.lib)libc.lib, libcmt.lib, msvcrt.lib, libcmtd.lib, msvcrtd.lib
Debug Multithreaded (libcmtd.lib)libc.lib, libcmt.lib, msvcrt.lib, libcd.lib, msvcrtd.lib
Debug Multithreaded using DLL (msvcrtd.lib)/NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib

Parenthesis Matching

  1. Place the cursor to the left of the parenthesis you want to find the mate to.
  2. Type control   ]

Things that can be matched


Debugging, Don't step into


Debugging, Don't go into [Visual Studio.NET]

Note: The values are reread every time the debugger is restarted.

  1. Make sure to use 7.0 for Visual Studio.NET 2002, and 7.1 for 2003
  2. Add Registry Keys down to
    HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\7.0\NativeDE\StepOver
  3. Things to step over are String values there, with the name of the value being a number.
  4. The rules are executed in highest number to lowest number order
  5. Restarting the debugger picks up rules changes.

Example String Values for the Registry

# operator new()
operator new=NoStepInto

# It was impossible to stop it from debugging into:
# FXString& FXString::operator+=(const FXchar* s)
# until I did this:
.*FXString.*=NoStepInto

Some Values

What to AvoidValue
newoperator new=nostepinto
std:: (namespace)std\:\:.*=NoStepInto
MyNameSpace::MyClassMyNameSpace\:\:MyClass\:\:*=NoStepInto
Note: I haven't been able to figure out how/if 'scope' works sg_String:: (class)\\scope:sg_String\\:\\:.*=NoStepInto

Things can be turned back on as well, by using StepInto. Since higher numbered rules happen last you can disable stepping into all of a class except what you set to 'StepInto' in a higher numbered rule.

Examples

Don't go into new in Visual Studio.NET 2002. Use this .reg file:

Which creates the following (or you can do this by hand)

Or change the 7.0 to 7.1 for Visual Studio.NET 2003

Undigested info on this:


Debugging, Don't go into [Visual Studio 6]

  1. Edit C:\Program Files\Microsoft Visual Studio .NET\Common7\Packages\Debugger\AutoExp.dat
  2. Edit C:\Program Files\Microsoft Visual Studio 8\Common7\Packages\Debugger\AutoExp.dat
  3. Find or create a section named [ExecutionControl]
  4. Add lines as described below

Avoid commands

Function=NoStepInto Avoid stepping into this specific function
Classname::Method=NoStepInto Avoid stepping into the specific method of this class
Classname::*=NoStepInto Avoid stepping into any of the methods of this class

Examples


[ExecutionControl]
    CString::CString=NoStepInto
    CString::~CString=NoStepInto
    CString::operator==NoStepInto

Console App Debugging


Setting up a New install of Visual Studio


Dependancies, Program

Use depends.exe it get it as part of
Windows XP Service Pack 2 Support Tools


Exceptions, breaking when they are thrown

Use  Debug | Exceptions  to modify the exception processing behavior


Output, putting it elsewhere checklist

General | Output Directory.\..\..\root\usr\lib\ntx86debug
General | Intermediate Directory.\..\..\arch\ntx86debug\obj\$(ProjectName)
Linker | General | Output File.\..\..\root\bin\ntx86debug\$(InputName).dll
Linker | Debug | Generate Program Database File.\..\..\root\bin\ntx86debug\$(InputName).pdb
Linker | Advanced | Import Library.\..\..\root\usr\lib\ntx86debug\$(InputName).lib

Watch Window

Format Specifiers

SpecifierFormatValueDisplays
d,isigned decimal integer0xF000F065-268373915
uunsigned decimal integer0x0065101
ounsigned octal integer0xF0650170145
x,XHexadecimal integer61541 (decimal)0x0000F065
l,hlong or short prefix for: d, i, u, o, x, X00406042,hx0x0c22
fsigned floating point3./2.1.500000
esigned scientific notation3./2.1.500000e+000
gsigned floating point or signed scientific notation, whichever is shorter3./2.1.5
cSingle character0x0065101 'e'
sString0x0012fde8"Hello world"
suUnicode string "Hello world"
hrHRESULT or Win32 error code. (The debugger now decodes HRESULTs automatically, so this specifier is not required in those cases. It is not possible to decode HRESULTs if you compile with /noHRESULT).0x00000000LS_OK
wcWindow class flag.0x00000040 WC_DEFAULTCHAR
wmWindows message numbers0x0010WM_CLOSE

Memory Display Specifiers

SymbolFormatDisplays
ma64 ASCII characters0x0012ffac .4...0...".0W&.......1W&.0.:W..1...."..1.JO&.1.2.."..1...0y....1
m16 bytes in hexadecimal, followed by 16 ASCII characters 0x0012ffac B3 34 CB 00 84 30 94 80 FF 22 8A 30 57 26 00 00 .4...0...".0W&..
mb16 bytes in hexadecimal, followed by 16 ASCII characters 0x0012ffac B3 34 CB 00 84 30 94 80 FF 22 8A 30 57 26 00 00 .4...0...".0W&..
mw8 words0x0012ffac 34B3 00CB 3084 8094 22FF 308A 2657 0000
md4 doublewords0x0012ffac 00CB34B3 80943084 308A22FF 00002657
mq2 quadwords0x0012ffac 7ffdf00000000000 5f441a790012fdd4
mu2-byte characters (Unicode)0x0012fc60 8478 77f4 ffff ffff 0000 0000 0000 0000

pMem,10  // shows it as an array of 10 elements
pMem,100m  // shows it as an array of 100 elements in memory dump format

Custom display of Objects

Note: The file is reread every time the debugger is restarted.

Modify the autoexp.dat file as shown HERE

autoexp.dat file locations

AppDefault Location
Visual Studio.NET
also known as VS8.0
C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Packages\Debugger

Examples to use in autoexp.dat

; These must go in the [AutoExpand] section of the file
[AutoExpand]

NameSpaceHere::ClassnameHere =DescToShow=<field.subfield>
; the above makes the value display like the followning:
; 0x12345678 DescToShow={value at field.subfield}

Visio

Visio will work from Visual Studio


HTML Editor Setup


"Cannot Write ... dll" problem with COM and .NET Interop

Seems to only happen when there are connection points in the COM dll

It seems to keep the COM dll open when it builds the InteropFile

To make things work, add a custom build step to the COM dll (at midl compile time, or at the end of everything), that does this:

tlbimp ../../root/usr/lib/%ARCHM%/$(InputName).tlb /out:../../root/usr/lib/%ARCHM%/Interop.$(InputName).dll

And in the .NET project add a Reference to the Interop.{name}.dll that is created in the custom build step above.


Sound Scheme

Start | Control Panel | Sounds, Speech, and Audio Devices | Sounds