The hook procedure must be located in a DLL for it to be global. You will meet some additional challenges when it comes to writing down to a shared file resource, though, but for now you should just focus on getting the hook DLL running. I believe there are examples of global hooks on both MSDN and e.g. www.codeproject.com, so you should turn your attention there.
Just as a side note; writing keyloggers isn't usually what people would want to help you with on these forums, so don't expect anyone to provide all the code for you
