DECLARE LONG GetLastError IN Win32APIImmediately after WriteFile call the function. The return value should indicate why the code is failing. If you have Visual Studio installed, there's a tool called error lookup that gives you the error message. Or just post the code here.