I have written a small piece of code to open/close a cd/dvd drive tray using the DeviceIoControl API and the proper IOCTL but I don\'t seem to be able to check the tray stat
Well, the documentation for this API states that it returns whether there is a disk in the drive and nothing about whether the tray is open or not. The specific requirements as to which error code is returns is not documented. I get 21 in both situations too.
I reviewed the documentation and could not find any documented way to do what you asked. To most applications, whether or not the tray is open is not that interesting.