Index: /trunk/include/iprt/cdefs.h
===================================================================
--- /trunk/include/iprt/cdefs.h	(revision 15833)
+++ /trunk/include/iprt/cdefs.h	(revision 15834)
@@ -802,5 +802,5 @@
  */
 /** @def RT_UNLIKELY
- * Give the compiler a hint that an expression is highly unlikely hold true.
+ * Give the compiler a hint that an expression is highly unlikely to hold true.
  *
  * See the usage instructions give in the RT_LIKELY() docs.
Index: /trunk/src/VBox/Main/SessionImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/SessionImpl.cpp	(revision 15833)
+++ /trunk/src/VBox/Main/SessionImpl.cpp	(revision 15834)
@@ -266,13 +266,13 @@
     AutoReadLock alock (this);
 
-    AssertReturn (mState != SessionState_Closed, E_FAIL);
+    AssertReturn (mState != SessionState_Closed, VBOX_E_INVALID_VM_STATE);
 
     AssertMsgReturn (mType == SessionType_Direct && !!mConsole,
-                     ("This is not a direct session!\n"), E_FAIL);
+      ("This is not a direct session!\n"), VBOX_E_INVALID_OBJECT_STATE);
 
     /* return a failure if the session already transitioned to Closing
      * but the server hasn't processed Machine::OnSessionEnd() yet. */
     if (mState != SessionState_Open)
-        return E_UNEXPECTED;
+        return VBOX_E_INVALID_VM_STATE;
 
     mConsole.queryInterfaceTo (aConsole);
@@ -291,5 +291,5 @@
     AutoWriteLock alock (this);
 
-    AssertReturn (mState == SessionState_Closed, E_FAIL);
+    AssertReturn (mState == SessionState_Closed, VBOX_E_INVALID_VM_STATE);
 
     if (!aMachine)
@@ -302,5 +302,5 @@
          */
 
-        AssertReturn (mType == SessionType_Null, E_FAIL);
+        AssertReturn (mType == SessionType_Null, VBOX_E_INVALID_OBJECT_STATE);
         mType = SessionType_Remote;
         mState = SessionState_Spawning;
@@ -363,5 +363,5 @@
 
     AssertReturn (mState == SessionState_Closed ||
-                  mState == SessionState_Spawning, E_FAIL);
+                  mState == SessionState_Spawning, VBOX_E_INVALID_VM_STATE);
 
     HRESULT rc = E_FAIL;
@@ -369,5 +369,5 @@
     /* query IInternalMachineControl interface */
     mControl = aMachine;
-    AssertReturn (!!mControl, E_FAIL);
+    AssertReturn (!!mControl, E_FAIL); // This test appears to be redundant --JS
 
     /// @todo (dmik)
@@ -445,6 +445,6 @@
     }
 
-    AssertReturn (mState == SessionState_Open &&
-                  mType == SessionType_Direct, E_FAIL);
+    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
+    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
     AssertReturn (!mControl.isNull(), E_FAIL);
@@ -476,5 +476,5 @@
 
         AssertReturn (mState == SessionState_Open ||
-                      mState == SessionState_Spawning, E_FAIL);
+                      mState == SessionState_Spawning, VBOX_E_INVALID_VM_STATE);
 
         /* close ourselves */
@@ -509,6 +509,6 @@
 
     AutoReadLock alock (this);
-    AssertReturn (mState == SessionState_Open &&
-                  mType == SessionType_Direct, E_FAIL);
+    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
+    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onDVDDriveChange();
@@ -523,6 +523,6 @@
 
     AutoReadLock alock (this);
-    AssertReturn (mState == SessionState_Open &&
-                  mType == SessionType_Direct, E_FAIL);
+    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
+    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onFloppyDriveChange();
@@ -537,6 +537,6 @@
 
     AutoReadLock alock (this);
-    AssertReturn (mState == SessionState_Open &&
-                  mType == SessionType_Direct, E_FAIL);
+    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
+    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onNetworkAdapterChange(networkAdapter);
@@ -551,6 +551,6 @@
 
     AutoReadLock alock (this);
-    AssertReturn (mState == SessionState_Open &&
-                  mType == SessionType_Direct, E_FAIL);
+    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
+    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onSerialPortChange(serialPort);
@@ -565,6 +565,6 @@
 
     AutoReadLock alock (this);
-    AssertReturn (mState == SessionState_Open &&
-                  mType == SessionType_Direct, E_FAIL);
+    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
+    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onParallelPortChange(parallelPort);
@@ -579,6 +579,6 @@
 
     AutoReadLock alock (this);
-    AssertReturn (mState == SessionState_Open &&
-                  mType == SessionType_Direct, E_FAIL);
+    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
+    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onVRDPServerChange();
@@ -593,6 +593,6 @@
 
     AutoReadLock alock (this);
-    AssertReturn (mState == SessionState_Open &&
-                  mType == SessionType_Direct, E_FAIL);
+    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
+    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onUSBControllerChange();
@@ -607,6 +607,6 @@
 
     AutoReadLock alock (this);
-    AssertReturn (mState == SessionState_Open &&
-                  mType == SessionType_Direct, E_FAIL);
+    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
+    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onSharedFolderChange (aGlobal);
@@ -623,6 +623,6 @@
 
     AutoReadLock alock (this);
-    AssertReturn (mState == SessionState_Open &&
-                  mType == SessionType_Direct, E_FAIL);
+    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
+    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onUSBDeviceAttach (aDevice, aError, aMaskedIfs);
@@ -638,6 +638,6 @@
 
     AutoReadLock alock (this);
-    AssertReturn (mState == SessionState_Open &&
-                  mType == SessionType_Direct, E_FAIL);
+    AssertReturn (mState == SessionState_Open, VBOX_E_INVALID_VM_STATE);
+    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onUSBDeviceDetach (aId, aError);
@@ -651,5 +651,5 @@
     AutoReadLock alock (this);
 
-    AssertReturn (mType == SessionType_Direct, E_FAIL);
+    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
 
     if (mState != SessionState_Open)
@@ -678,5 +678,5 @@
             tr ("Machine session is not open (session state: %d)."),
             mState);
-    AssertReturn (mType == SessionType_Direct, E_UNEXPECTED);
+    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
     CheckComArgNotNull(aName);
     if (!aIsSetter && !VALID_PTR (aRetValue))
@@ -712,8 +712,8 @@
 
     if (mState != SessionState_Open)
-        return setError (E_FAIL,
+        return setError (VBOX_E_INVALID_VM_STATE,
             tr ("Machine session is not open (session state: %d)."),
             mState);
-    AssertReturn (mType == SessionType_Direct, E_UNEXPECTED);
+    AssertReturn (mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
     if (!VALID_PTR (aPatterns) && (aPatterns != NULL))
         return E_POINTER;
Index: /trunk/src/VBox/Main/idl/VirtualBox.xidl
===================================================================
--- /trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 15833)
+++ /trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 15834)
@@ -11144,5 +11144,15 @@
 
     <method name="getRemoteConsole">
-      <desc>Returns the console object suitable for remote control.</desc>
+      <desc>
+        Returns the console object suitable for remote control.
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Session state prevents operation.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Session type prevents operation.
+        </result>
+
+      </desc>
       <param name="console" type="IConsole" dir="return"/>
     </method>
@@ -11152,5 +11162,13 @@
         Assigns the machine object associated with this direct-type
         session or informs the session that it will be a remote one
-        (if machine = NULL).
+        (if @a machine == NULL).
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Session state prevents operation.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Session type prevents operation.
+        </result>
+
       </desc>
       <param name="machine" type="IMachine" dir="in"/>
@@ -11161,4 +11179,9 @@
         Assigns the machine and the (remote) console object associated with
         this remote-type session.
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Session state prevents operation.
+        </result>
+
       </desc>
       <param name="machine" type="IMachine" dir="in"/>
@@ -11171,4 +11194,12 @@
         Must be called only in certain cases
         (see the method implementation).
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Session state prevents operation.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Session type prevents operation.
+        </result>
+
       </desc>
       <param name="aMachineState" type="MachineState" dir="in"/>
@@ -11180,4 +11211,9 @@
         the corresponding remote session when the direct session dies
         or gets closed.
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Session state prevents operation.
+        </result>
+
       </desc>
     </method>
@@ -11187,4 +11223,12 @@
         Triggered when settings of the DVD drive object of the
         associated virtual machine have changed.
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Session state prevents operation.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Session type prevents operation.
+        </result>
+
       </desc>
     </method>
@@ -11194,4 +11238,12 @@
         Triggered when settings of the floppy drive object of the
         associated virtual machine have changed.
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Session state prevents operation.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Session type prevents operation.
+        </result>
+
       </desc>
     </method>
@@ -11201,4 +11253,12 @@
         Triggered when settings of a network adapter of the
         associated virtual machine have changed.
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Session state prevents operation.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Session type prevents operation.
+        </result>
+
       </desc>
       <param name="networkAdapter" type="INetworkAdapter" dir="in"/>
@@ -11209,4 +11269,12 @@
         Triggered when settings of a serial port of the
         associated virtual machine have changed.
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Session state prevents operation.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Session type prevents operation.
+        </result>
+
       </desc>
       <param name="serialPort" type="ISerialPort" dir="in"/>
@@ -11217,4 +11285,12 @@
         Triggered when settings of a parallel port of the
         associated virtual machine have changed.
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Session state prevents operation.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Session type prevents operation.
+        </result>
+
       </desc>
       <param name="parallelPort" type="IParallelPort" dir="in"/>
@@ -11225,4 +11301,12 @@
         Triggered when settings of the VRDP server object of the
         associated virtual machine have changed.
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Session state prevents operation.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Session type prevents operation.
+        </result>
+
       </desc>
     </method>
@@ -11232,4 +11316,12 @@
         Triggered when settings of the USB controller object of the
         associated virtual machine have changed.
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Session state prevents operation.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Session type prevents operation.
+        </result>
+
       </desc>
     </method>
@@ -11245,4 +11337,12 @@
           time of processing this notification.
         </note>
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Session state prevents operation.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Session type prevents operation.
+        </result>
+
       </desc>
       <param name="global" type="boolean" dir="in"/>
@@ -11256,4 +11356,12 @@
         A @c null @a error object means success, otherwise it
         describes a failure.
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Session state prevents operation.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Session type prevents operation.
+        </result>
+
       </desc>
       <param name="device" type="IUSBDevice" dir="in"/>
@@ -11268,4 +11376,12 @@
         <link to="IConsole::detachUSBDevice"/>) has completed.
         A @c null @a error object means success, otherwise it
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Session state prevents operation.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Session type prevents operation.
+        </result>
+
       </desc>
       <param name="id" type="uuid" dir="in"/>
@@ -11280,4 +11396,9 @@
         <link to="IConsoleCallback::onCanShowWindow()"/>
         and <link to="IConsoleCallback::onShowWindow()"/>.
+
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Session type prevents operation.
+        </result>
+
       </desc>
       <param name="check" type="boolean" dir="in"/>
@@ -11291,4 +11412,12 @@
         <link to="IMachine::setGuestProperty()"/> in order to read and
         modify guest properties.
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Machine session is not open.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Session type is not direct.
+        </result>
+
       </desc>
       <param name="name" type="wstring" dir="in"/>
@@ -11305,4 +11434,12 @@
         Return a list of the guest properties matching a set of patterns along
         with their values, time stamps and flags.
+
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Machine session is not open.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Session type is not direct.
+        </result>
+
       </desc>
       <param name="patterns" type="wstring" dir="in">
