Is the DWORD length=pFileName.sizeof; setting length to the size of the pointer, when you need the length of the string? That would explain why only 4 bytes have been written.