Develop win rebased

Pathces for issue #646

Hope something of this compatibity code could be useful
This one does compile on Linux too (checked on old RHEL with custom-built gcc 4.7.2 and libaries from sources)