Added Windows support for bgd.dll and fixed a condition that could cause...

... segmentation fault.