The code calibre uses to eject devices on windows is a self contained exe file. It is the best I could code up with from the undocumented mess that is win32 apis for device management. Am happy to accept improvements for it:
https://github.com/kovidgoyal/calibr...indows/eject.c