EXE-self-modification and protected mode

Hi all,

after following the recent discussion on self-modification of EXE-files
I've encountered another problem. Here it is:

After implementing one or another of the given solutions (they are based
on the same facts, more or less) and "making it go" in real mode I
encountered problems when recompling the (working) source code for the
protected mode target. In the moment of "resetting" the EXE-file the
IO-error 162 stops the program.
Any ideas of how to solve this "little" problem?

Thanx,

Bernd Heutling