WriteFile wants a pointer not a handle so you should be passing "Locked" instead of "SoundRes", do you get the same error using it?