You may see, using Visual C++ warnings like:
First-chance exception at 0x12345678 in app.exe: 0xC0000001: Access
violation reading location 0x12345678.
First-chance exceptions can be seen even if the EXE does not crash and the Task Manager does not show any significant memory leaks. If a program uses exception handling then it can mean that the program successfully handled the exception.
The debugger is notified when these occur. It then passes it back to the program. If the program does not handle it, it returns to the debugger. This is a second-chance exception. Typically, a debugger will stop. If there is no debugger then the program will likely crash.
If you are concerned then you can set the Visual C++ debugger to break on first chance exceptions, via:
Useful web pages
Running in Debug mode within Visual C++ with an application built using the /MTd compiler flag will cause lots of debugging information and memory leak info to be displayed e.g.
{13983} normal block at 0x027844A8, 23 bytes long.
Data: <C:/test.img > 43 3A 2F 61 61 61 61 61 61 61 61 2E 69 6D 67 00
{13982} normal block at 0x02784460, 23 bytes long.
Data: <C:/test.hdr > 43 3A 2F 61 61 61 61 61 61 61 61 2E 68 64 72 00
{13981} normal block at 0x027841A0, 660 bytes long.
Data: < P > 04 00 00 00 00 01 00 00 00 01 00 00 50 00 00 00
Visual C++ Express allows C++ to be compiled in Debug mode or Release mode.
For example, in VTK, if you mix them up e.g. a Release mode VTK application and a Debug mode VTK library then you may get an error relating to vtkInformationStringKey e.g. see http://www.vtk.org/pipermail/vtkusers/2006-October/087761.html.
Or, for wxWidgets-related classes, you may get linker errors with code LNK1120: 1 unresolved externals.
For more information, see http://stackoverflow.com/questions/367884/debug-release-difference
For VTK, if you build in Debug mode then you need to beware if moving certain directories about e.g. Debug mode seems to assume that the VTK binary directory does not move.
Static libraries have .lib extension, runtime/dynamic libraries have .dll extension.
If /MD is used you've built a runtime library. Applications using these assume that the DLL is in one of:
C:\Windows\system directory. C:\Windows\system32 directory. SetDllDirectory() to specify where they should be. To create a standalone exe requires the /MT option to be set which means create a "multi-threading and a static library".
If you get an error like:
This application has failed to start because the application configuration is incorrect.
This was because the program was compiled by default by Visual Studio using the /MD runtime library option which means "uses multi-threading and DLL runtime library" and means that msvcr80.dll must be available at runtime. VTK, by default, is also built using this option.
For more information, see
c:\test\test.cpp(21) : fatal error C1010: unexpected end of file
while looking for precompiled header directive.
This can arise if the project expects pre-compiled headers and your code is missing an: #include"stdafx.h"
To enable/disable pre-compiled headers:
Visual C++ projects can either be ANSI or Unicode. If there are problems then you will get an error like:
error C2664: ... cannot convert parameter 2 from 'constchar [4]' to 'LPCWSTR' 1>
Types pointed to are unrelated; conversion requires reinterpret_cast,
C-stylecastor function-stylecast
You can change encoding by:
Unicode is recommended
Visual C++ Express doesn't support editing of these so to create a resource file do:
.h file .rc .rc file To toggle between /MT and /MD do:
/MD to /MT In Visual C++ project files the values are:
RuntimeLibrary="0" for /MTRuntimeLibrary="1" for /MTdRuntimeLibrary="2" for /MD - default RuntimeLibrary="3" for /MDd Set the Properties => General => Configuration Type to Static Library (.lib).
To add the above as a pre-requisite in an other project:
$(SolutionDir)\MyLib$(SolutionDir)\$(ConfigurationName)MyLib.lib If using the JPEG library, you may need to edit the project properties to exclude the libc.lib library. To do this:
libc.lib.