Friday, July 21, 2006

VC ++ tips and tricks ( interesting)













1. Debug build works, Release build doesn't ??

This is the single most common posting made to programming forums and usenet. The answer is simple - fix the bug in your code!!! The reason you are experiencing problems is usually due to uninitialized variables in functions or classes. Problems like this are present in both Debug and Release builds, but typically only manifest themselves in the release binary because the debug build is alot more tolerant to errors.

2. Fix Intellisense problems

This is the most frustrating "feature" of Visual Studio - when intellisense stops working. Simply exit Visual Studio and browse to your project directory - then delete the .ncb file for your project. When you restart Visual Studio the problem will be fixed.

3. Auto-indent current selection

Press Alt+F8 on any highlighted text in the code-editor, and the code will be automatically adjusted so that each line is at the correct indentation level. Selecting an entire function body properly indents each line within the function.

4. Define custom keywords

Visual C++ has the ability to highlight user-defined keywords in your code. The colour of these user-defined keywords is easily adjusted using the Options dialog, but adding user-defined keywords is not documented.

Simply create a file called "usertype.dat" in your C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin directory (the same directory that contains MSDEV.EXE). The contents of this file is a series of custom keywords, each one on a separate line. These keywords do not need to contain the built-in types such as int, char etc - only additional keywords that you want highlighted.

Here is the usertype.dat I use on my development machine. This same tip applies to Visual Studio.NET - look in the C:\Program Files\Visual Studio.NET\Common7\IDE directory (where DEVENV.EXE lives) and place your usertype.dat file there.

5. Define custom colours in the IDE

The Visual C++ IDE only allows you to select from 16 different colours. If you are fussy about the these colours then you can modify the base 16 colours from the following registry location:

HKCU\Software\Microsoft\Devstudio\6.0\Format\Source Window\

Inside this key there are a series of binary data items, one for each user-definable entity in the source window - such as comments, keywords, strings and normal text. Each value is made up using the same format. The first four bytes are the foreground colour, in RGBA format (3 bytes for RGB and 1 byte for padding). The background colour follows immediately afterwards using the same format:

 [ RR GG BB xx ][ RR GG BB xx ]
Foreground Background

You can use the Registry Editor to Export and Import your colour settings from machine-to-machine.

6. Column-based selection

The Visual studio editor lets you select text in a line-by-line manner. However, holding the ALT key down whilst making a selection with the mouse causes columns of text to be selected rather than rows (lines).s

7. View structure members

Position the cusor next to the same of a structure variable and press CTRL+SPACE. The structure members popup window will appear.

8. View function parameters

Position the cursor on/after the name of a function and press CTRL+SHIFT+SPACE. The function-parameters popup window will appear.

9. Display Disassembly

Whilst debugging a project, press ALT+8 to switch to assembler mode.

10. Find Definition of any identifier

Right-click the mouse on any variable, function, structure or macro. A popup menu will appear - select "Goto Definition Of". Usually an error box will appear stating that you need to rebuild your project with browse information. Click YES, and wait for the project to rebuild. Now when you "Goto Definition Of", Visual C++ will open the appropriate source / header file and jump to the line containing the definition of the item you just selected.

11. Bookmark lines of text

You can bookmark lines of text for further reference, using the "Mark" commands. Press Ctrl+F2 to mark/unmark a line of text. Press F2 to skip between marked positions within each source-file.

The list of current bookmarks can be displayed by the Edit -> Bookmarks dialog or by pressing ALT+F2.

12. Callgraphs

Position the cursor over any function name and hit ALT+F12. If your project was built with browse-information, a dialog will appear asking what you want to do. Select CallGraph to view a hierarchy of all sub-functions which are called by your function. This is a very useful feature often overlooked in Visual Studio.

13. Navigate around your source quickly

Hold down Control whilst using the Arrow Keys to make the cursor skip between words, rather than moving character-by-character.

14. Find corresponding brackets

Position the cursor over any "{", "[", "(", "}", "]" or ")" bracket and hit CTRL+"]". The cursor will move to the corresponding opening/closing bracket of that expression.

15. Show/Hide whitespace

Press CTRL+SHIFT+8 to show / hide whitespace markers.

16. Open header files

Right-click any filename in your source-code (i.e. in a string expression or #include line) and click "Open Document". Visual Studio will open the corresponding file in the IDE.

17. Installing Platform SDK

The simplest method to install a new SDK or DDK is to install the entire package to a new location on your hard-disk (rather than install over the old one). I always recommend storing SDKs and MSDN help libraries in a "simple" directory location so it is easy to browse to using the command-prompt. i.e.

C:\MSVS\SDK2004\
C:\MSVS\MSDN2004\

When you want to integrate this new SDK into Visual C++, bring up the Tools->Options dialog box, and select the "Directories" tab. There is a drop-down list which lets you entire directories for Include files (*.h) and Library files (*.lib). Enter a new directory location for the following paths and move them to the top of their respective lists:

C:\MSVS\SDK2004\Include
C:\MSVS\SDK2004\Lib

When Visual C++ compiles your project, it first searches the specified directories for include and library files. By putting the new directories at the top of the list it searches those first, before resorting to the "default" locations.

18. Preserve Keyboard and Layout settings

Visual Studio's keyboard and layout settings are stored in the following locations:

HKEY_CURRENT_USER\Software\Microsoft\DevStudio\6.0\Keyboard
HKEY_CURRENT_USER\Software\Microsoft\DevStudio\6.0\Layout

Use REGEDIT to Export these registry locations to an external file, then simply Import the settings when you need them on any new machine.

19. Using MAP files

You can see exactly what functions and global variables have been compiled into your project by looking at the corresponding MAP file in your /Debug or /Release directory. To enable this feature, open the Project->Settings dialog and select the "Linker" tab. Make sure the "Generate Map File" checkbox is selected.

20. Generate assembly-language output

You can see the full assembly language output of your project (complete with corresponding source-line and op-code output). Open the Project->Settings dialog and select the "C/C++" tab. Select the "Listing Files" option from the drop-down list and then select what type of output you want. The resulting file is generated in your /Debug or /Release directory.

21. Tiny Executables!

Generate instantly smaller executables by performing the following steps:

  1. Open the Project Settings dialog from the Project menu.
  2. Select the C/C++ tab
  3. Select Code Generation from the Category combo-box.
  4. In the Use run-time library drop-down-list, select:

    Debug Multithreaded DLL for Debug builds
    Multithreaded DLL for Release builds

Now add the following line to the top of your main source file and you will have instantly smaller exes:

#pragma comment(linker, "/OPT:NOWIN98")

22. Breakpoints Dialog

It is very easy to miss the Breakpoints dialog from the Edit menu (what a strange place to put it!).

However some very powerful debugging can be achieved. Set breakpoints when specific variables change in value, when a Window procedure is called with a certain window-message, or when other conditions are met.

23. Edit Executable Resources

Visual Studio is a fully functional binary resource editor. Simply open an executable or dll using the File->Open dialog, but before pressing OK, select the "Resources" option in the "Open As" drop-down-list. You can use this feature to edit menus, dialogs, strings and bitmaps in regular executables and dlls such as notepad, paint, wordpad etc.

24. Display Workspace window

Press Alt+0 (Alt+zero) at any time to bring up the Project Workspace window.

25. Debug Release Builds

It is possible (and usually desirable) to generate debug information for your release builds. This is advantageous because you can now debug problems that only manifest themselves in a release-build environment. You can do this in such a way that the debug information is not stored inside the executable (thus bloating it up) - instead, it is stored in a separate .pdb (program database) file. The only entry in the executable is a small string which directs the debugger to your program database, so you can distribute the executable without this sensitive information.

Select "Link" from the Project->Settings dialog, and then select "Debug" from the Category drop-down list. Make sure that the "Debug Info" checkbox is selected, and then enable "COFF Format".

Now for any source-file that you want debugging information generated for, select that file (or your entire project) in the Project->Settings dialog, and then make sure that the "Program Database" option is enabled in the C/C++ General-settings tab.

26. Warning Level 4

Catch more errors in your project by enabling "Warning Level 4" in the C/C++ General settings tab.

27. Console and Window applications

You can switch between Console and Win32 applications at any time by editing the Linker options manually in the "Project Options" edit-field under the Project->Settings->Link dialog. Edit the /SUBSYSTEM option to switch between console and gui builds. i.e.

/SUBSYSTEM:CONSOLE

/SUBSYSTEM:WINDOWS

28. Generate Browse Information

Select Generate Browse Info under the C/C++ project settings tab, for any source-files that you want to be included. This is very useful for searching for function definitions and declarations - just right-click a function / variable and select "Goto Definition Of..." and the IDE will take you straight there.

29. Visual Studio Debugger - Watch Window

There are many useful commands available in the watch window, which can alter the way variables and error values are displayed by the debugger.

Command Description
eax Displays the return value of a function after it returns.
@err Display the current Win32 GetLastError value
string,su Display the specified string as Unicode.
value,hr Treat the specified value as a HRESULT and display it's string representation
value,wm Decode the specified value as a Windows Message.
value,x Display value in Hexadecimal
array,23 Display exactly 23 elements of the specified array

30. Avoid stepping into CRT functions

The reason the Visual Studio debugger steps into CRT functions (i.e. into new/delete) when you don't want it to, is because you installed the source-code to the CRT/MFC libraries. Either move the source-code to a different location, or prevent the Visual Studio debugger from stepping into specific functions (whilst pressing F11) by performing the following steps:

  1. Open AUTOEXP.DAT (from the COMMON\MSDEV98\BIN\ directory)
  2. Add a section called [ExecutionControl]
  3. Add a line in this section with the following format:

    functionName=NoStepInfo
    className::*=NoStepInfo

  4. Restart the IDE for the changes to take effect.

Of course as soon as you accidently step into a function that you didn't want to be in, simply press SHIFT+F11 to step out again.

Thursday, July 13, 2006

Some Interesting BLOGS


*A personal collection of bookmarked links of resources and articles about Web design and Web production.
http://www.bobbyvandersluis.com/main/linkLibrary.php

*Microsoft most valued professional..site(good one)
http://msmvps.com/blogs/omar/default.aspx

ASP.NET "Atlas" documentation includes topics, tutorials, samples, and Webcast videos. We suggest the following documentation to help you get started.
http://atlas.asp.net/docs/default.aspx

***Very good article
StickOut is a desktop sticky note with multi-user support and Outlook integration. As a .NET Framework 2.0 Windows Forms application, it uses .NET Remoting to communicate with other StickOut users and exchange sticky notes with them.
http://msdn.microsoft.com/netframework/default.aspx?pull=/library/en-us/dnwinforms/html/stickout.asp

**RSS Feeder its good
http://rssfeederdotnet.sourceforge.net/

**For UML Class Diagram
http://smartuml.sourceforge.net/

Wednesday, July 05, 2006

Sites More Specific to DESIGN PATTERNS


very important one
**
http://home.earthlink.net/%7Ehuston2/dp/patterns.html

http://home.earthlink.net/%7Ehuston2/dp/patterns.html
http://home.earthlink.net/%7Ehuston2/dp/strategy.html
http://home.earthlink.net/%7Ehuston2/ps/mastermind_article.html
http://home.earthlink.net/%7Ehuston2/dp/patterns_quiz.html
http://www.cmcrossroads.com/bradapp/docs/patterns-nutshell.html
http://www.hillside.net/patterns/onlinepatterncatalog.htm
http://hillside.net/patterns/EuroPLoP2002/papers.html
http://www.abstractspoon.com/

to do list.. implementation very good one
we can see the implementation and the executable..try to dig from architecture perspective.
http://www.codeproject.com/tools/ToDoList2.asp

LINK : warning LNK4098: defaultlib "LIBCD" conflicts with use of other libs

Modules are most obvious at link time: the application in example one must be linked with the 3 user libraries and then system libraries. This is where a particularly ugly linking problem can occur in Visual C++.
LINK : warning LNK4098: defaultlib "LIBCD" conflicts with use of other libs;
use /NODEFAULTLIB:library
What this error really means is something like: one part of the system was compiled to use a single threaded standard (libc) library with debug information (libcd) which is statically linked, while another part of the system was compiled to use a multi-threaded standard library without debug information which resides in a DLL and uses dynamic linking, or some something similar.
In fact VC++ comes with no fewer than six versions of the standard library: debug and non-debug, singlethreaded and multi-threaded, .lib resident and .dll resident – there is no single threaded DLL version of the libraries.
Once this error appears people normally check their project settings run-time library choice. However, this is only part of the story and can actually be the start of many frustrating hours. Microsoft allow developers to imbed directives (#pragma comment(lib,....) ) in their own libraries which tell the linker which standard library this library expects to be linked with. These directives are all equal in the linkers eyes, so if your application is built for debug mutli-thread DLL and one of the libraries is set for single threaded debug you will have a conflict. Even though the project settings clearly say one thing the linker will try to also link an alternative.

The best way to fix this problem is to trawl through all your libraries and ensure they have the correct link settings. This can be very time consuming, particular as each one may need re-building. So, you have three options
? Ignore the warning, after all it is only a warning. However, your program now contains multiple instances of the same functions. If you are lucky you will quickly see an really obscure memory access violation, chances are the memory was allocated from one pool (say the libc, single threaded non-debug library) and freed to another (say, MSVCRTD, the multi-thread dynamic debug library). If you are unlucky things will work for you and a customer will encounter this problem.
? Use the linker option, /NODEFAULT:lib as suggested above, or even /FORCE. This is not a complete solution, even if you can get your program to link this way you are ignoring a warning sign: the code has been compiled for different environments, some of your code may be compiled for a single threaded model while other code is multi-threaded.
? Trawl through your libraries and ensure that everyone is set to the same settings.
However, even this is not guaranteed to work! There are two common problems here:
? You have a third party library which is linked differently to your application.
Sidebox: Microsoft libraries (Sidebox.rtf) 5-Dec-01
? You have other directives embedded in your code: normally this is the MFC. If any modules in your system link against MFC all your modules must nominally link against the same version of MFC. In reality this is not much of a bind, although your code may be set to link against MFC if the libraries will only be pulled in if something from them is used.
This can all be very boring and frustrating to track through your code. However, it’s not that bad, there are a few tools you can use to look inside libraries.
? dumpbin supplied with VC++ has several options which can be helpful but /DIRECTIVES it probably
the most useful.
? depends is a tool supplied with the NT resource kit can drill down into the DLL loaded by a program.
(Actually, there are two versions of depends, a command line tool and a much nicer GUI one.)
? pview (supplied with both VC++ and the resouce kit can show which DLLs are loaded. However, it is
quite normal to see MSVCRT and MSVCRTD (debug version) loaded at the same time as much
Microsoft code itself uses MSVCRT.
In addition, if you follow these rules you should be OK:
? Decide which library you want to link against and stick with it for everything: normally this means
dynamic multi-threaded debug and release. If you are using MFC you don’t really have a choice.
? Ensure any third party libraries have this dependency (or better still none at all.)
? Never use /NODEFAULT:lib or /FORCE : once this problem enters your quickly ripples through
everything, you can’t allow exceptions.
? Never select “ignore default libraries” : it doesn’t work very well anyway.
? Never use #pragma comment(lib,....) yourself. It introduces a hidden dependency.
Finally, the best solution as ever is to understand what is happening. Understand what libraries Microsoft
supplies and is forcing on you.

Monday, July 03, 2006

Round Trip Engineering

* There is some concept called "Round Trip Sync Engineering".
It is combination of "Forward Engineering and Reverse Engineering". Forward engineering is Implementing the Design Diagrams(ie class diagrams etc.,) first and then code according to them. And reverse engineering is vice versa.

* Rational Model has implemented this concept "Round Trip Engineering".Its interface is flexible enough that based on the class diagrams we created, the generic code frame(header files and cpp files) and has automaticalled generated by that tool. We have to implemet the logic in functions to which the function is meant for.

*It also generates code for associations,aggregations etc., between the classes.