I can't see your code so don't know for sure.
You may have a simple pointer bug or you aren't using VirtualProtect correctly.
Here's an example similar to what you're doing.
http://stackoverflow.com/questions/13461771/hooks-why-do-we-need-to-virtualprotect-again-to-restore-permissions[
^]
Normally, you use VirtualProtect to make the memory executable
and read-write, make a copy, overwrite the original, and restore execute only access with VirtualProtect.
If you write a single function to do this, it can be used both for setting and restoring the hooked API function.