This Blog Has Been Moved !

This Blog Has been moved to http://aleemkhan.wordpress.com



The Interviews with Microsoft were like this J

I found this and tweaked it a little to show the MS Interview Process … .lol

Bye !

It is really amazing how the .NET Framework has made the development tasks easier. The Framework Class Library is undoubtedly an extremely rich set of API’s. I wanted to dump the entire address space of any process. So, I thought of doing a small Dump Tool in the free time which I get occasionally in the evenings or on weekends. I’ll post the complete code when it’s complete.

Anyway I wrote the following C++ code to get SeDebugPrivilige for a process. SeDebugPrivilige allows any process to access memory and other information of operating system processes which you do not have access to otherwise.

BOOL CTaskManagerDlg::SetPrivilege()

{

   HANDLE hToken;
   TOKEN_PRIVILEGES tp;
   LUID luid;
   TOKEN_PRIVILEGES tpPrevious;
   DWORD cbPrevious=sizeof(TOKEN_PRIVILEGES);

   if(!OpenProcessToken(::GetCurrentProcess(),
   TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&hToken))
     return FALSE;

   if(!LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &luid ))
     return FALSE;
   tp.PrivilegeCount           = 1;
   tp.Privileges[0].Luid       = luid;
   tp.Privileges[0].Attributes = 0;

   AdjustTokenPrivileges(hToken,FALSE,&tp,
   sizeof(TOKEN_PRIVILEGES),&tpPrevious,&cPrevious);
   if (GetLastError() != ERROR_SUCCESS)
     return FALSE;

   tpPrevious.PrivilegeCount       = 1;
   tpPrevious.Privileges[0].Luid   = luid;
   tpPrevious.Privileges[0].Attributes|=(SE_PRIVILEGE_ENABLED);

   AdjustTokenPrivileges(hToken,FALSE, &tpPrevious,cbPrevious,
   NULL,NULL);
   if (GetLastError() != ERROR_SUCCESS)
     return FALSE;

   CloseHandle(hToken);
   return TRUE;

}

This code has been taken mostly from the MSDN Article Article ID: Q131065

To do all this from C# you just need to call a simple function J

 

System.Diagnostics.Process.EnterDebugMode();

Yes ! Its that easy. The Base Class Library is quite rich but you only have to find the things. However, I still could not find the equivalent of Functions from the native ToolHelp32 library defined in the Kernel32.dll. So, I have to write a complete PInvoke wrapper for that. I will post the complete code on the weekend.

 

Can anyone tell me where to find .NET Equivalents of  ToolHelp32 Functions ?

 

Today I bought a new System. Pentium-IV 3.0 GHz and 17" LG Flatron Monitor :). Now I have two systems on my desktop. A Linux machine and a Windows machine. I am really anxious for checking out the New Team Foundation Server that I have recently recieved. Microsoft is Sending a Free 4 DVD Pack containing the Visual Studio 2005 Beta, Team Foundation Server and SQL Server 2005 (YUKON) with another DVD with some learning material. You can register too From the MSDN Visual Studio Developer Center.

Just installing a few softwares. I usually have a lot of softwares on board... and I've to transfer 50 GB of data too .... so its gonna take the night today, but tomorrow is a Sunday anyway......
Brad Abrams Posted a small Equality Quiz

Its just 10 min but it was fun. Here are my answers (Try yoursellf first)
public static void Question1()
{
int x = 10;
long y = 10;
Console.WriteLine(x==y && !x.Equals(y));
}
public static void Question2()
{
object x = 10;
object y = 10;
Console.WriteLine(x!=y && x.Equals(y));
}
public static void Question3()
{
object x = new object();
int y = 10;
Console.WriteLine(x==y);
}
public static void Question4()
{
int x = 10;
int y = 10;
Console.WriteLine(x == y && (object)x!=(object)y);
}

Ok! I said I’ll be sharing some of the MS Interview experience. For the preparation of the interview we (with my other friends) searched various resources on the internet. I even purchased an e-book but it didn’t turn out to be helpful. Generally there are three types of questions in an MS Interview. Analytical/Puzzles, Algorithms/Coding and Personality. We collected various questions in these categories.

Following are some of the Logical/Analytical questions generally asked at MS. There are a lot of questions but the following are the most common and are mentioned by various people who have been through the interviews. Frankly, before the interview I thought that this was some good set of questions but they will not ask these questions which you find so easily on the internet, or probably these questions are too old, but they do ask these questions repeatedly and sometimes they even know that you have done this question before but just to observe your reaction.

Anyway, even I got atleast 5-6 questions from the following set. It’s a good exercise, I’ll see if I get some time to post the answers to these over the next weekend. Wait for Coding/Algorithm questions in future posts.

Logical/Puzzles Questions Usually Asked at Microsoft

  1. Why is a manhole cover round?
  2. If you had an infinite supply of water and a 5 quart and 3 quart pail, how would you measure exactly 4 quarts?
  3. You have 5 jars of pills. Each pill weighs 10 gram, except for contaminated pills contained in one jar, where each pill weighs 9 gm. Given a scale, how could you tell which jar had the contaminated pills in just one measurement?
  4. If you are on a boat and you throw out a suitcase, will the level of water increase or decrease?
  5. How many times a day a clock's hands overlap?
  6. One train leaves Los Angeles at 15mph heading for New York. Another train leaves from New York at 20mph heading for Los Angeles on the same track. If a bird, flying at 25mph, leaves from Los Angeles at the same time as the train and flies back and forth between the two trains until they collide, how far will the bird have traveled?
  7. There are 3 ants at 3 corners of a triangle; they randomly start moving towards another corner. What is the probability that they don't collide?
  8. If you look at a clock and the time is 3:15, what is the angle between the hour and the minute hands? (The answer to this is not zero!)
  9. How would you weigh a plane without using scales
  10. Why are beer cans tapered at the top and bottom?
  11. You have 8 balls. One of them is defective and weighs less than others. You have a balance to measure balls against each other. In 2 weighings how do you find the defective one?
  12. There are 3 baskets. one of them have apples, one has oranges only and the other has mixture of apples and oranges. The labels on their baskets always lie. (i.e. if the label says oranges, you are sure that it doesn’t have oranges only,it could be a mixture) The task is to pick one basket and pick only one fruit from it and then correctly label all the three baskets.
  13. Given a rectangular (cuboidal for the puritans) cake with a rectangular piece removed (any size or orientation), how would you cut the remainder of the cake into two equal halves with one straight cut of a knife?
  14. If you have two buckets, one with red paint and the other with blue paint, and you take one cup from the blue bucket and poor it into the red bucket. Then you take one cup from the red bucket and poor it into the blue bucket. Which bucket has the highest ratio between red and blue? Prove it mathematically.
  15. You have a bucket of jelly beans. Some are red, some are blue, and some green. With your eyes closed, pick out 2 of a like color. How many do you have to grab to be sure you have 2 of the same?
  16. You are given a scale which you are to use to measure eight balls. Seven of these balls have the same weight: the eigth ball is heavier than the rest. What is the minimum number of weighs you could perform to find the heaviest of the eight balls?.
  17. Pairs of primes separated by a single number are called prime pairs. Examples are 17 and 19. Prove that the number between a prime pair is always divisible by 6 (assuming both numbers in the pair are greater than 6). Now prove that there are no 'prime triples.'
  18. There is a room with a door (closed) and three light bulbs. Outside the room there are three switches, connected to the bulbs. You may manipulate the switches as you wish, but once you open the door you can't change them. Identify each switch with its bulb.
  19. There are 4 women who want to cross a bridge. They all begin on the same side. You have 17 minutes to get all of them across to the other side. It is night. There is one flashlight. A maximum of two people can cross at one time. Any party who crosses, either 1 or 2 people, must have the flashlight with them. The flashlight must be walked back and forth, it cannot be thrown, etc. Each woman walks at a different speed. A pair must walk together at the rate of the slower woman's pace.
    Woman 1: 1 minute to cross
    Woman 2: 2 minutes to cross
    Woman 3: 5 minutes to cross
    Woman 4: 10 minutes to cross
    For example if Woman 1 and Woman 4 walk across first, 10 minutes have elapsed when they get to the other side of the bridge. If Woman 4 then returns with the flashlight, a total of 20 minutes have passed and you have failed the mission. What is the order required to get all women across in 17 minutes? Now, what's the other way?

There is a good discussion available on MSDN with “Anders Hejlsberg”, the lead Architect of C# language. The discussion focuses on various new features in C# and their comparison with C++ and Java, like Generics in C#, Checked and Un-Checked exceptions and other topics. It’s a useful reading.

http://msdn.microsoft.com/vcsharp/homepageheadlines/hejlsberg/

There is a small problem with System.Drawing.dll in VS.NET 2003. Sometimes you get an Arithmetic Exception and the program is terminated. If u get this "Arithmetic Exception" in System.Drawing.dll, then there must be some spy software or some virus installed on your system which has hooked the system and changed the FPU (FloatingPoint Unit value) for all the processes.

To Set the FPU value to dafault u can use _controlfp() function defined in "msvcrt.dll". This is a native function, to call this function in C# u will have to use .NET Runtime Interop Services. To do this add the following lines of code to your Form class

[DllImport("msvcrt.dll")]
private static extern int _controlfp(int n, int mask);
private const int _MCW_EW = 0x8001F;
private const int _EM_INVALID = 0x10;

Now call this function at the start of your form constructor

_controlfp(_MCW_EW, _EM_INVALID);

The FPU value is now set to default and you will not get any Exception in system.Drawing.dll

Ohh ! Finally my Blog is set. For the last one month I have been trying to setup my Blog. In the process I went through various Blogging Engines. I downloaded and setup Community Server on my local machine and explored it a little. It was interesting to know that MSDN Blogs is also using the Community Server.

On this Blog I will be sharing my personal experiences/learning and all the stuff that I go through the internet. I’ll try to keep up with the posts, queries and comments. My prime focus these days is .NET Framework/C# and Longhorn, so I think I’ll be saying things about that.

Recently, I had the experience of being interviewed by Microsoft. Though, I could not get through but reaching the final step, going on a sponsored trip to Dubai and then having those 4 final interviews with some of top guys at Microsoft was an experience of a lifetime. I’ll try to share that also in the coming days.