Thursday, May 26, 2011

Run as administrator in Windows 7

To create a manifest for a C or C++ project in Microsoft Visual Studio 2005

1. Open your project in Microsoft Visual Studio 2005.

2. Under Project, select Properties.

3. In Properties, select Manifest Tool, and then select Input and Output.

4. Add in the name of your application manifest file under Additional manifest files. A sample manifest file is given below.

5. Rebuild your application.


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
   <ms_asmv2:trustInfo xmlns:ms_asmv2="urn:schemas-microsoft-com:asm.v2">
      <ms_asmv2:security>
         <ms_asmv2:requestedPrivileges>
            <ms_asmv2:requestedExecutionLevel level="requireAdministrator">
            </ms_asmv2:requestedExecutionLevel>
         </ms_asmv2:requestedPrivileges>
      </ms_asmv2:security>
   </ms_asmv2:trustInfo>
</assembly>

Wednesday, April 27, 2011

No pointers.. No Glory

I have seen many fresh candidates who show up for C/C++ jobs and they don't know anything about pointers. Some of junior S/W engineers don't know pointers as well. This is really disappointing :( Here are some basics that everyone should know.

int VAR = 10;

What this declaration really says is:
1. There is some memory reserved for VAR
2. Size of this memory is 4 bytes as sizeof(int) == 4
3. content of this memory is 10

Usually everyone know this, but there is one more detail that people forget
4. There is an address of the memory... we can assume for now that memory for VAR starts from 0x0400 to 0x0403. We call this address of VAR.

But how can we really know what is the address of VAR. That's simple!

cout << &VAR;

& is a construct of C that can be used to get the address of any variable. &VAR is also called reference of VAR. Above statement will print the actual address of VAR.

Now we declare a pointer

int *PTR = &VAR; //also means int * PTR = 0x0400;

This declaration means
1. There is some memory reserved for PTR
2. Size of this memory is 4 bytes as all pointers are of 4 bytes in 32 bit architecture
3. content of this memory is 0x0400
4. There is an address of the memory... we can assume for now that memory for PTR starts from 0x0800 to 0x0803. We call this address of PTR.


Here is what we get in following statements.

1. cout << VAR; //10
2. cout << &VAR; //0x0400
3. cout << PTR; //0x0400
4. cout << &PTR; //0x0800

Now how to use PTR to access VAR? For that C gives us a construct *. An asterisk (*) and an ampersand (&) are opposite to each other. & gets address of a variable while * gets variable from an address.

*PTR
using cout 3: *PTR == *(0x0400)
using cout 2: *(0x0400) = *(&VAR)
we know sin(cosin(x)) == x similarly * and & cancel each other out so
*(&VAR) = VAR

So
cout << *PTR; //10
cout << var; //10