How to generate XML Schema from XML file?

22 11 2009


Ever wondered how to generate XML schema from XML file?
Indeed, a lot of 3ed party tools can do it for you. But as usual, any easy way?


You can use Visual Studio IDE itself to generate XSD from XML file. Follow the steps.

1) Open the XML file in Visual Studio IDE.
2) Take View > Other Windows > Command Window.
3) Now type and execute command – XML.CreateSchema
4) See, the schema is generated.


A hidden pearl in VS IDE. Isn’t it?


Targeted Audience – Beginners.

Advertisements




Search for Symbols in Visual Studio more Easily

15 11 2009


Ever tried VisualAssist? Yes man, Its a killer product. The feature that I like most is its Symbol Search. You can specify words and it will list symbols that contain those words. Its very useful if you have a vague idea about the function name that you’re searching for. Have a look at the following screenshot.

Search3FindInVisualStudio

But is there any PoorMan’s SearchSymbols without VisualAssist?


Did you forget about the hidden gem in VisualStudio find window? Yes, the Regular Expressions. You can use .* to do the same search done by VisualAssist. For instance, to do the above search, search for Show.*Msg. Have a look at following screenshots.

Search4

Now look at the results. Cool! isn’t it?

Search5


Quite easy. nah? BTW, did you try to kill that bug. 😉


Targeted Audience – Beginners.





How to Watch this Pointer – The Wizards Way!

30 07 2009


How to watch the this pointer? Just add ‘this’ to watch window. Everyone does like that. Isn’t it? But how Visual C++ wizards watch ‘this’ pointer? 😉

thiswizardway


The secret is, visual C++ compiler passes this pointer via ECX register. So add (ClassName*)(@ECX) to watch window will give you this pointer. Have a look at the screenshot.

thiswizardway2


Interesting, the internals of Visual C++. Isn’t it?


Targeted Audiance – Intermediate.





How to Watch Variables in Binary by using Visual Studio Debugger?

1 01 2009


In visual studio you can watch variable values in different formats. For instance, for viewing in hex add this to watch window – var,x and for octal – var,o. But its a pity that visual studio doesn’t support displaying variables in binaries. So how can you watch the value of a variable in binary, with debugger? 😉

watchvarinbinary_1
Image Courtesy – Pixdaus.


Well, we have to utilize the special feature of visual studio debugger. Basically the watch window is not just a tool to display the variable value. It can evaluate and execute small code snippets as well. If you add a function call to the watch window, that function will be called when debugger refreshes the watch values. So, all you have to do is – Add a global function which accepts integer value, converts it to binary string then display it to output window. Have a look at the function.

// Global function which converts integer to binary
// and dump to the output window.
void DumpBinary( DWORD Value )
{
    // Buffer to hold the converted string.
    TCHAR Buffer[255] = { 0 };

    // Convert the value to binary string.
    _itot( Value, Buffer, 2 );

    // Display to output window.
    CString csMessage;
    csMessage.Format( _T("\n%d in binary: %s"), Value, Buffer );
    OutputDebugString( csMessage );
}

Now if you want to convert the 100 to binary, break at some location and just add DumpBinary(100) to watch window and check the output in the output window. See the screenshot below.

watchvarinbinary


Just now I realized – how powerful the Visual Studio Debugger is. Hats off to Visual Studio Team!

Well, please note that in visual studio 2008 and may be in siblings, When you add this to watch window, its possible to see this error – “CXX0001: Error: error attempting to execute user function”. In that case just click the “Evaluate button” which appears next to it and the expression will be re-evaluate.

advancedseries
Targeted Audiance – Advanced.





How to find the Relative Path to other Common Folders – More Easily?

16 12 2008


Well you know what a relative path is. The “.\..\..\Folder” thing. Usually in project settings, while referring the path of other common include folders, relative path is being used. Because, it won’t break the project settings even though the entire development folder structure is moved from one location to another.

To be more specific, If you have specified absolute path like – “c:\Source\BlahBlahProject\Libs” in the project settings, if you move Source folder to D:\ your project won’t compile. Relative paths are good, but its a bit difficult to calculate it. I saw people calculating it with their memory by touching the folder structure in monitor. 😉 Some advanced guys uses the windows explorer’s auto complete feature to get the relative path. But is there any other easy method to get it?

relativepath


Well, You can use Visual Studio for it. Just follow the steps. Assume you want to get the relative path from your project folder to the common lib folder – “c:\Source\BlahBlahProject\Libs”.

1) Load you project in visual studio.
2) Create a file hello.cpp in folder – “c:\Source\BlahBlahProject\Libs”.
3) Add the file to your project by using menu – Project > Add To Project > Files.
4) Right click the file and take Properties.
relativepath1

5) In the properties, you can get the relative path from “Persist as” editbox.
relativepath2


The only limitation is our imagination. Isn’t it? 😉


Targeted Audience – Intermediate.





How to import dialogs or resources from one project to another?

9 09 2008


Designing dialogs – that could grab a good amount of time! But often we can find dialogs that can be reused from our previous projects. But the copy paste trick – the Ctrl+C & Ctrl+V won’t work on dialog resources. So how to copy/paste dialogs or any other resources from one project to another?

importdialog


Assume you have two projectsProject1 and project2 and you want to copy one dialog from Project1 to Project2. Just follow the steps –

For Visual Studio 6.0
1) Load project2 workspace in visual studio.
2) Now Browse and load Project1’s rc file. While opening resource file, select “Open As” as “Resources”.

3) Now drag your required dialog from project1’s resource tree and drop it to your resource tree.

4) You’ve successfully copied dialog from one project to another!

For Visual Studio 2005 and siblings
1) Open your IDE without any solutions loaded.
2) open both RC files into the IDE.
3) Now take Project2 RC file, right click on the dialog you want to export and copy it.

importdialog1

4) Now take Project1 RC file, right click and paste.

importdialog2

5) You see, now the dialog is imported from project1 to Project2.

importdialog3

Well, special thanks to Mike and Alan for their contribution for the trick in Visual Studio 2005.


You could also edit the rc file in some text editor and can copy paste the dialog if you’re a geek. 😉


Targeted Audience – Beginners.





How to add ampersand(&) symbol to dialog control captions?

15 06 2008


For dialog controls we can assign keyboard accelerators. If you give the button text as “&Add”, then really it will become Add” because the ampersand character is used to mark the keyboard accelerator for that control. But what to do if you want the button text to be “Add & Refresh“?


Just use && if you want ampersand as part of caption instead of Keyboard accelerator marker. For instance see the screenshot.


Targeted Audience – Beginners.