Your program worked ok for me using vc++ 2010 express on Windows 7. But I don't understand why it contains a while(1) loop? One possible reason that it crashes on you is because the code never calls GlobalUnlock().
>>when I copy a file the program crashes
Copy a from to where? I don't understand that statement.