Index: /trunk/include/VBox/com/string.h
===================================================================
--- /trunk/include/VBox/com/string.h	(revision 42569)
+++ /trunk/include/VBox/com/string.h	(revision 42570)
@@ -559,4 +559,60 @@
     bool operator<(const RTCString &that) const { return RTCString::operator<(that); }
 
+    /**
+     * Extended assignment method that returns a COM status code instead of an
+     * exception on failure.
+     *
+     * @returns S_OK or E_OUTOFMEMORY.
+     * @param   a_rSrcStr   The source string
+     */
+    HRESULT assignEx(Utf8Str const &a_rSrcStr)
+    {
+        return copyFromExNComRC(a_rSrcStr.m_psz, a_rSrcStr.m_cch);
+    }
+
+    /**
+     * Extended assignment method that returns a COM status code instead of an
+     * exception on failure.
+     *
+     * @returns S_OK, E_OUTOFMEMORY or E_INVALIDARG.
+     * @param   a_pcszSrc   The source string
+     * @param   a_offSrc    The character (byte) offset of the substring.
+     * @param   a_cchSrc    The number of characters (bytes) to copy from the source
+     *                      string.
+     */
+    HRESULT assignEx(Utf8Str const &a_rSrcStr, size_t a_offSrc, size_t a_cchSrc)
+    {
+        if (   a_offSrc + a_cchSrc > a_rSrcStr.m_cch
+            || a_offSrc > a_rSrcStr.m_cch)
+            return E_INVALIDARG;
+        return copyFromExNComRC(a_rSrcStr.m_psz, a_rSrcStr.m_cch);
+    }
+
+    /**
+     * Extended assignment method that returns a COM status code instead of an
+     * exception on failure.
+     *
+     * @returns S_OK or E_OUTOFMEMORY.
+     * @param   a_pcszSrc   The source string
+     */
+    HRESULT assignEx(const char *a_pcszSrc)
+    {
+        return copyFromExNComRC(a_pcszSrc, a_pcszSrc ? strlen(a_pcszSrc) : 0);
+    }
+
+    /**
+     * Extended assignment method that returns a COM status code instead of an
+     * exception on failure.
+     *
+     * @returns S_OK or E_OUTOFMEMORY.
+     * @param   a_pcszSrc   The source string
+     * @param   a_cchSrc    The number of characters (bytes) to copy from the source
+     *                      string.
+     */
+    HRESULT assignEx(const char *a_pcszSrc, size_t a_cchSrc)
+    {
+        return copyFromExNComRC(a_pcszSrc, a_cchSrc);
+    }
+
     RTMEMEF_NEW_AND_DELETE_OPERATORS();
 
@@ -655,4 +711,5 @@
     void copyFrom(CBSTR a_pbstr);
     HRESULT copyFromEx(CBSTR a_pbstr);
+    HRESULT copyFromExNComRC(const char *a_pcszSrc, size_t a_cchSrc);
 
     friend class Bstr; /* to access our raw_copy() */
Index: /trunk/src/VBox/Main/glue/string.cpp
===================================================================
--- /trunk/src/VBox/Main/glue/string.cpp	(revision 42569)
+++ /trunk/src/VBox/Main/glue/string.cpp	(revision 42570)
@@ -241,3 +241,44 @@
 }
 
+
+/**
+ * A variant of Utf8Str::copyFromN that does not throw any exceptions but
+ * returns E_OUTOFMEMORY instead.
+ *
+ * @param   a_pcszSrc   The source string.
+ * @param   a_cchSrc    The source string.
+ * @returns S_OK or E_OUTOFMEMORY.
+ *
+ * @remarks This calls cleanup() first, so the caller doesn't have to. (Saves
+ *          code space.)
+ */
+HRESULT Utf8Str::copyFromExNComRC(const char *a_pcszSrc, size_t a_cchSrc)
+{
+    cleanup();
+    if (a_cchSrc)
+    {
+        m_psz = RTStrAlloc(a_cchSrc + 1);
+        if (RT_LIKELY(m_psz))
+        {
+            m_cch = a_cchSrc;
+            m_cbAllocated = a_cchSrc + 1;
+            memcpy(m_psz, a_pcszSrc, a_cchSrc);
+            m_psz[a_cchSrc] = '\0';
+        }
+        else
+        {
+            m_cch = 0;
+            m_cbAllocated = 0;
+            return E_OUTOFMEMORY;
+        }
+    }
+    else
+    {
+        m_cch = 0;
+        m_cbAllocated = 0;
+        m_psz = NULL;
+    }
+    return S_OK;
+}
+
 } /* namespace com */
