+1  A: 

Don't write this kind of code yourself. Use the Detours library from Microsoft Research.

Hans Passant
I know that i should not write this kind of code myself.But I am writing it for experimental purposes, and to see that I am able to write this kind of code. I want to know about the bug in the Program.Anyway,Thank you for answering my Question.
desaiparth
You can't write code like this if you don't know how to debug it. It should be part of the experiment perhaps. Somebody else debugging this for you doesn't help you write and debug this kind of code in the future. Good luck!
Hans Passant
I know how to debug this kind of program and i am debugging it for last two days. But I have not found any bug so I am asking in stackoverflow .Anyway I have found some interesting information during debugging That have been added to the Question. Take a Look.
desaiparth
The compiler expects the called function to preserve the value of the esi register. That's not happening for the redirected function. Not sure why, look at the assembly code of the replacement function. The compiler might have optimized it, passing the arguments through registers. Because it doesn't have external linkage perhaps.
Hans Passant