Index: /trunk/src/VBox/Frontends/VBoxHeadless/FramebufferVNC.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxHeadless/FramebufferVNC.cpp	(revision 30199)
+++ /trunk/src/VBox/Frontends/VBoxHeadless/FramebufferVNC.cpp	(revision 30200)
@@ -59,15 +59,18 @@
 }
 
-
-VNCFB::~VNCFB() {
+VNCFB::~VNCFB()
+{
     LogFlow(("Destroying VNCFB object %p\n", this));
     RTCritSectDelete(&mCritSect);
-    if (vncServer) {
-    if (vncServer->authPasswdData) {
-        char **papszPassword = (char **)vncServer->authPasswdData;
-        vncServer->authPasswdData = NULL;
-        RTMemFree(papszPassword[0]);
-        RTMemFree(papszPassword);
-    }
+    if (vncServer)
+    {
+        RTStrFree((char*)vncServer->desktopName);
+        if (vncServer->authPasswdData)
+        {
+            char **papszPassword = (char **)vncServer->authPasswdData;
+            vncServer->authPasswdData = NULL;
+            RTMemFree(papszPassword[0]);
+            RTMemFree(papszPassword);
+        }
         rfbScreenCleanup(vncServer);
     }
@@ -78,5 +81,6 @@
 }
 
-HRESULT VNCFB::init() {
+HRESULT VNCFB::init(const char *pszName)
+{
     LogFlow(("Initialising VNCFB object %p\n", this));
     int rc = RTCritSectInit(&mCritSect);
@@ -85,16 +89,22 @@
     vncServer = rfbGetScreen(0, NULL, mWidth, mHeight, 8, 3, 1);
     vncServer->screenData = (void*)this;
-    if (mVncPort) vncServer->port = mVncPort;
-    vncServer->desktopName = "VirtualBox";
-
-    if (mVncPassword) {
-    char **papszPasswords = (char **)RTMemAlloc(2 * sizeof(char **));
+    if (mVncPort)
+        vncServer->port = mVncPort;
+    char *pszDesktopName;
+    rc = RTStrAPrintf(&pszDesktopName, "%s - VirtualBox", pszName);
+    if (RT_SUCCESS(rc))
+        vncServer->desktopName = (const char*)pszDesktopName;
+    else
+        vncServer->desktopName = "VirtualBox";
+    if (mVncPassword)
+    {
+        char **papszPasswords = (char **)RTMemAlloc(2 * sizeof(char **));
         papszPasswords[0] = RTStrDup(mVncPassword);
         papszPasswords[1] = NULL;
-    vncServer->authPasswdData = papszPasswords;
+        vncServer->authPasswdData = papszPasswords;
         vncServer->passwordCheck = rfbCheckPasswordByList; //Password list based authentication function
-    } else {
-    vncServer->authPasswdData = NULL;
-    }
+    }
+    else
+        vncServer->authPasswdData = NULL;
 
     rfbInitServer(vncServer);
@@ -114,4 +124,9 @@
 }
 
+void VNCFB::enableAbsMouse(bool fEnable)
+{
+    fAbsMouseEnabled = fEnable;
+}
+
 DECLCALLBACK(int) VNCFB::vncThreadFn(RTTHREAD hThreadSelf, void *pvUser)
 {
@@ -120,14 +135,18 @@
 }
 
-void VNCFB::vncMouseEvent(int buttonMask, int x, int y, rfbClientPtr cl) {
+void VNCFB::vncMouseEvent(int buttonMask, int x, int y, rfbClientPtr cl)
+{
     ((VNCFB*)(cl->screen->screenData))->handleVncMouseEvent(buttonMask, x, y);
     rfbDefaultPtrAddEvent(buttonMask, x, y, cl);
 }
 
-void VNCFB::handleVncMouseEvent(int buttonMask, int x, int y) {
+void VNCFB::handleVncMouseEvent(int buttonMask, int x, int y)
+{
     //RTPrintf("VNC mouse: button=%d x=%d y=%d\n", buttonMask, x, y);
-    if (!mMouse) {
+    if (!mMouse)
+    {
         this->mConsole->COMGETTER(Mouse)(mMouse.asOutParam());
-        if (!mMouse) {
+        if (!mMouse)
+        {
             RTPrintf("Warning: could not get mouse object!\n");
             return;
@@ -135,34 +154,54 @@
     }
     int dz = 0, buttons = 0;
-    if (buttonMask & 16) dz = 1; else if (buttonMask & 8) dz = -1;
-    if (buttonMask & 1) buttons |= 1;
-    if (buttonMask & 2) buttons |= 4;
-    if (buttonMask & 4) buttons |= 2;
-    mMouse->PutMouseEvent(x - mouseX, y - mouseY, dz, 0, buttons);
-    //mMouse->PutMouseEventAbsolute(x + 1, y + 1, dz, 0, buttonMask);
+    if (buttonMask & 16)
+        dz = 1;
+    else if (buttonMask & 8)
+        dz = -1;
+    if (buttonMask & 1)
+        buttons |= 1;
+    if (buttonMask & 2)
+        buttons |= 4;
+    if (buttonMask & 4)
+        buttons |= 2;
+    if (fAbsMouseEnabled)
+        mMouse->PutMouseEventAbsolute(x, y, dz, 0, buttons);
+    else
+        mMouse->PutMouseEvent(x - mouseX, y - mouseY, dz, 0, buttons);
     mouseX = x;
     mouseY = y;
 }
 
-void VNCFB::kbdPutCode(int code) {
+void VNCFB::kbdPutCode(int code)
+{
     mKeyboard->PutScancode(code);
 }
-void VNCFB::kbdSetShift(int state) {
-    if (state && !kbdShiftState) {
+
+void VNCFB::kbdSetShift(int state)
+{
+    if (state && !kbdShiftState)
+    {
         kbdPutCode(0x2a, 1);
         kbdShiftState = 1;
-    } else if (!state && kbdShiftState) {
+    }
+    else if (!state && kbdShiftState)
+    {
         kbdPutCode(0x2a, 0);
         kbdShiftState = 0;
     }
 }
-void VNCFB::kbdPutCode(int code, int down) {
-    if (code & 0xff00) kbdPutCode((code >> 8) & 0xff);
+void VNCFB::kbdPutCode(int code, int down)
+{
+    if (code & 0xff00)
+        kbdPutCode((code >> 8) & 0xff);
     kbdPutCode((code & 0xff) | (down ? 0 : 0x80));
 }
-void VNCFB::kbdPutCodeShift(int shift, int code, int down) {
-    if (shift != kbdShiftState) kbdPutCode(0x2a, shift);
+
+void VNCFB::kbdPutCodeShift(int shift, int code, int down)
+{
+    if (shift != kbdShiftState)
+        kbdPutCode(0x2a, shift);
     kbdPutCode(code, down);
-    if (shift != kbdShiftState) kbdPutCode(0x2a, kbdShiftState);
+    if (shift != kbdShiftState)
+        kbdPutCode(0x2a, kbdShiftState);
 }
 
@@ -171,9 +210,12 @@
  * Now we're using one lookup table for the lower X11 key codes (ASCII characters)
  * and a switch() block to handle some special keys. */
-void VNCFB::handleVncKeyboardEvent(int down, int keycode) {
+void VNCFB::handleVncKeyboardEvent(int down, int keycode)
+{
     //RTPrintf("VNC keyboard: down=%d code=%d -> ", down, keycode);
-    if (mKeyboard == NULL) {
+    if (mKeyboard == NULL)
+    {
         this->mConsole->COMGETTER(Keyboard)(mKeyboard.asOutParam());
-        if (!mKeyboard) {
+        if (!mKeyboard)
+        {
             RTPrintf("Warning: could not get keyboard object!\n");
             return;
@@ -188,5 +230,7 @@
      * This is necessary because the VNC protocol sends a shift key sequence, but also
      * sends the 'shifted' version of the characters. */
-    static int codes_low[] = { //Conversion table for VNC key code range 32-127
+    static int codes_low[] =
+    {
+        //Conversion table for VNC key code range 32-127
         0x0239, 0x0102, 0x0128, 0x0104, 0x0105, 0x0106, 0x0108, 0x0028, 0x010a, 0x010b, 0x0109, 0x010d, 0x0029, 0x000c, 0x0034, 0x0035, //space, !"#$%&'()*+`-./
         0x0b, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, //0123456789
@@ -198,12 +242,24 @@
     };
     int shift = -1, code = -1;
-    if (keycode < 32) { //ASCII control codes.. unused..
-    } else if (keycode < 127) { //DEL is in high area
+    if (keycode < 32)
+    {
+        //ASCII control codes.. unused..
+    }
+    else if (keycode < 127)
+    {
+        //DEL is in high area
         code = codes_low[keycode - 32];
-        shift = (code >> 8) & 0x03; if (shift == 0x02 || code & 0xe000) shift = -1;
+        shift = (code >> 8) & 0x03;
+        if (shift == 0x02 || code & 0xe000)
+            shift = -1;
         code = code & 0xe0ff;
-    } else if ((keycode & 0xFF00) != 0xFF00) {
-    } else {
-        switch(keycode) {
+    }
+    else if ((keycode & 0xFF00) != 0xFF00)
+    {
+    }
+    else
+    {
+        switch(keycode)
+        {
 /*Numpad keys - these have to be implemented yet
 Todo: numpad arrows, home, pageup, pagedown, end, insert, delete
@@ -273,13 +329,19 @@
     }
     //RTPrintf("down=%d shift=%d code=%d\n", down, shift, code);
-    if (shift != -1 && code != -1) {
+    if (shift != -1 && code != -1)
+    {
         kbdPutCodeShift(shift, code, down);
-    } else if (shift != -1) {
+    }
+    else if (shift != -1)
+    {
         kbdSetShift(shift);
-    } else if (code != -1) {
+    }
+    else if (code != -1)
+    {
         kbdPutCode(code, down);
     }
 }
-void VNCFB::handleVncKeyboardReleaseEvent() {
+void VNCFB::handleVncKeyboardReleaseEvent()
+{
     kbdSetShift(0);
     kbdPutCode(0x1d, 0); //Left ctrl
@@ -289,8 +351,12 @@
 }
 
-void VNCFB::vncKeyboardEvent(rfbBool down, rfbKeySym keySym, rfbClientPtr cl) {
+void VNCFB::vncKeyboardEvent(rfbBool down, rfbKeySym keySym, rfbClientPtr cl)
+{
     ((VNCFB*)(cl->screen->screenData))->handleVncKeyboardEvent(down, keySym);
 }
-void VNCFB::vncReleaseKeysEvent(rfbClientPtr cl) { //Release modifier keys
+
+void VNCFB::vncReleaseKeysEvent(rfbClientPtr cl)
+{
+    //Release modifier keys
     ((VNCFB*)(cl->screen->screenData))->handleVncKeyboardReleaseEvent();
 }
@@ -327,17 +393,21 @@
                                   BYTE *vram, ULONG bitsPerPixel,
                                   ULONG bytesPerLine,
-                                  ULONG w, ULONG h, BOOL *finished) {
+                                  ULONG w, ULONG h, BOOL *finished)
+{
     NOREF(aScreenId);
-    if (!finished) return E_POINTER;
+    if (!finished)
+        return E_POINTER;
 
     /* For now, we are doing things synchronously */
     *finished = true;
 
-    if (mRGBBuffer) RTMemFree(mRGBBuffer);
+    if (mRGBBuffer)
+        RTMemFree(mRGBBuffer);
 
     mWidth = w;
     mHeight = h;
 
-    if (pixelFormat == FramebufferPixelFormat_FOURCC_RGB && bitsPerPixel == 32) {
+    if (pixelFormat == FramebufferPixelFormat_FOURCC_RGB && bitsPerPixel == 32)
+    {
         mPixelFormat = FramebufferPixelFormat_FOURCC_RGB;
             mBufferAddress = reinterpret_cast<uint8_t *>(vram);
@@ -345,5 +415,7 @@
             mBitsPerPixel = bitsPerPixel;
             mRGBBuffer = NULL;
-    } else {
+    }
+    else
+    {
             mPixelFormat = FramebufferPixelFormat_FOURCC_RGB;
             mBytesPerLine = w * 4;
@@ -358,5 +430,6 @@
         AssertReturn(mScreenBuffer != 0, E_OUTOFMEMORY);
 
-    for (ULONG i = 0; i < mBytesPerLine * h; i += 4) {
+    for (ULONG i = 0; i < mBytesPerLine * h; i += 4)
+    {
         mScreenBuffer[i]   = mBufferAddress[i+2];
         mScreenBuffer[i+1] = mBufferAddress[i+1];
@@ -364,25 +437,28 @@
     }
 
-    RTPrintf("Set framebuffer: buffer=%d w=%lu h=%lu bpp=%d\n", mBufferAddress, mWidth, mHeight, (int)mBitsPerPixel);
+    RTPrintf("Set framebuffer: buffer=%llx w=%lu h=%lu bpp=%d\n",
+            (uint64_t)mBufferAddress, mWidth, mHeight, (int)mBitsPerPixel);
     rfbNewFramebuffer(vncServer, (char*)mScreenBuffer, mWidth, mHeight, 8, 3, mBitsPerPixel / 8);
-    if (oldBuffer) RTMemFree(oldBuffer);
+    if (oldBuffer)
+        RTMemFree(oldBuffer);
     return S_OK;
 }
 
 //Guest framebuffer update notification
-STDMETHODIMP VNCFB::NotifyUpdate(ULONG x, ULONG y, ULONG w, ULONG h) {
-    if (!mBufferAddress || !mScreenBuffer) return S_OK;
+STDMETHODIMP VNCFB::NotifyUpdate(ULONG x, ULONG y, ULONG w, ULONG h)
+{
+    if (!mBufferAddress || !mScreenBuffer)
+        return S_OK;
     ULONG joff = y * mBytesPerLine + x * 4;
     for (ULONG j = joff; j < joff + h * mBytesPerLine; j += mBytesPerLine)
-    for (ULONG i = j; i < j + w * 4; i += 4) {
-        mScreenBuffer[i]   = mBufferAddress[i+2];
-        mScreenBuffer[i+1] = mBufferAddress[i+1];
-        mScreenBuffer[i+2] = mBufferAddress[i];
-    }
+        for (ULONG i = j; i < j + w * 4; i += 4)
+        {
+            mScreenBuffer[i]   = mBufferAddress[i+2];
+            mScreenBuffer[i+1] = mBufferAddress[i+1];
+            mScreenBuffer[i+2] = mBufferAddress[i];
+        }
     rfbMarkRectAsModified(vncServer, x, y, x+w, y+h);
     return S_OK;
 }
-
-
 
 
@@ -396,6 +472,8 @@
  * @retval  address The address of the buffer
  */
-STDMETHODIMP VNCFB::COMGETTER(Address) (BYTE **address) {
-    if (!address) return E_POINTER;
+STDMETHODIMP VNCFB::COMGETTER(Address) (BYTE **address)
+{
+    if (!address)
+        return E_POINTER;
     LogFlow(("FFmpeg::COMGETTER(Address): returning address %p\n", mBufferAddress));
     *address = mBufferAddress;
@@ -409,6 +487,8 @@
  * @retval  width The width of the frame buffer
  */
-STDMETHODIMP VNCFB::COMGETTER(Width) (ULONG *width) {
-    if (!width) return E_POINTER;
+STDMETHODIMP VNCFB::COMGETTER(Width) (ULONG *width)
+{
+    if (!width)
+        return E_POINTER;
     LogFlow(("FFmpeg::COMGETTER(Width): returning width %lu\n", (unsigned long) mWidth));
     *width = mWidth;
@@ -422,6 +502,8 @@
  * @retval  height The height of the frame buffer
  */
-STDMETHODIMP VNCFB::COMGETTER(Height) (ULONG *height) {
-    if (!height) return E_POINTER;
+STDMETHODIMP VNCFB::COMGETTER(Height) (ULONG *height)
+{
+    if (!height)
+        return E_POINTER;
     LogFlow(("FFmpeg::COMGETTER(Height): returning height %lu\n", (unsigned long) mHeight));
     *height = mHeight;
@@ -439,6 +521,8 @@
  * @retval  bitsPerPixel The colour depth of the frame buffer
  */
-STDMETHODIMP VNCFB::COMGETTER(BitsPerPixel) (ULONG *bitsPerPixel) {
-    if (!bitsPerPixel) return E_POINTER;
+STDMETHODIMP VNCFB::COMGETTER(BitsPerPixel) (ULONG *bitsPerPixel)
+{
+    if (!bitsPerPixel)
+        return E_POINTER;
     *bitsPerPixel = mBitsPerPixel;
     LogFlow(("FFmpeg::COMGETTER(BitsPerPixel): returning depth %lu\n",
@@ -453,6 +537,8 @@
  * @retval  bytesPerLine The number of bytes per line
  */
-STDMETHODIMP VNCFB::COMGETTER(BytesPerLine) (ULONG *bytesPerLine) {
-    if (!bytesPerLine) return E_POINTER;
+STDMETHODIMP VNCFB::COMGETTER(BytesPerLine) (ULONG *bytesPerLine)
+{
+    if (!bytesPerLine)
+        return E_POINTER;
     LogFlow(("FFmpeg::COMGETTER(BytesPerLine): returning line size %lu\n", (unsigned long) mBytesPerLine));
     *bytesPerLine = mBytesPerLine;
@@ -466,6 +552,8 @@
  * @retval  pixelFormat The pixel layout
  */
-STDMETHODIMP VNCFB::COMGETTER(PixelFormat) (ULONG *pixelFormat) {
-    if (!pixelFormat) return E_POINTER;
+STDMETHODIMP VNCFB::COMGETTER(PixelFormat) (ULONG *pixelFormat)
+{
+    if (!pixelFormat)
+        return E_POINTER;
     LogFlow(("FFmpeg::COMGETTER(PixelFormat): returning pixel format: %lu\n", (unsigned long) mPixelFormat));
     *pixelFormat = mPixelFormat;
@@ -479,6 +567,8 @@
  * @retval  pixelFormat The pixel layout
  */
-STDMETHODIMP VNCFB::COMGETTER(UsesGuestVRAM) (BOOL *usesGuestVRAM) {
-    if (!usesGuestVRAM) return E_POINTER;
+STDMETHODIMP VNCFB::COMGETTER(UsesGuestVRAM) (BOOL *usesGuestVRAM)
+{
+    if (!usesGuestVRAM)
+        return E_POINTER;
     LogFlow(("FFmpeg::COMGETTER(UsesGuestVRAM): uses guest VRAM? %d\n", mRGBBuffer == NULL));
     *usesGuestVRAM = (mRGBBuffer == NULL);
@@ -493,6 +583,8 @@
  * @retval  heightReduction The number of unused lines
  */
-STDMETHODIMP VNCFB::COMGETTER(HeightReduction) (ULONG *heightReduction) {
-    if (!heightReduction) return E_POINTER;
+STDMETHODIMP VNCFB::COMGETTER(HeightReduction) (ULONG *heightReduction)
+{
+    if (!heightReduction)
+        return E_POINTER;
     /* no reduction */
     *heightReduction = 0;
@@ -508,6 +600,8 @@
  * @retval  aOverlay The overlay framebuffer
  */
-STDMETHODIMP VNCFB::COMGETTER(Overlay) (IFramebufferOverlay **aOverlay) {
-    if (!aOverlay) return E_POINTER;
+STDMETHODIMP VNCFB::COMGETTER(Overlay) (IFramebufferOverlay **aOverlay)
+{
+    if (!aOverlay)
+        return E_POINTER;
     /* not yet implemented */
     *aOverlay = 0;
@@ -522,6 +616,8 @@
  * @retval  winId Associated window id
  */
-STDMETHODIMP VNCFB::COMGETTER(WinId) (ULONG64 *winId) {
-    if (!winId) return E_POINTER;
+STDMETHODIMP VNCFB::COMGETTER(WinId) (ULONG64 *winId)
+{
+    if (!winId)
+        return E_POINTER;
     *winId = 0;
     return S_OK;
@@ -531,13 +627,16 @@
 /////////////////////////////////////////////////////////////////////////////
 
-STDMETHODIMP VNCFB::Lock() {
+STDMETHODIMP VNCFB::Lock()
+{
     LogFlow(("VNCFB::Lock: called\n"));
     int rc = RTCritSectEnter(&mCritSect);
     AssertRC(rc);
-    if (rc == VINF_SUCCESS) return S_OK;
+    if (rc == VINF_SUCCESS)
+        return S_OK;
     return E_UNEXPECTED;
 }
 
-STDMETHODIMP VNCFB::Unlock() {
+STDMETHODIMP VNCFB::Unlock()
+{
     LogFlow(("VNCFB::Unlock: called\n"));
     RTCritSectLeave(&mCritSect);
@@ -545,5 +644,4 @@
 }
 
-
 /**
  * Returns whether we like the given video mode.
@@ -551,6 +649,8 @@
  * @returns COM status code
  */
-STDMETHODIMP VNCFB::VideoModeSupported(ULONG width, ULONG height, ULONG bpp, BOOL *supported) {
-    if (!supported) return E_POINTER;
+STDMETHODIMP VNCFB::VideoModeSupported(ULONG width, ULONG height, ULONG bpp, BOOL *supported)
+{
+    if (!supported)
+        return E_POINTER;
     *supported = true;
     return S_OK;
@@ -558,6 +658,8 @@
 
 /** Stubbed */
-STDMETHODIMP VNCFB::GetVisibleRegion(BYTE *rectangles, ULONG /* count */, ULONG * /* countCopied */) {
-    if (!rectangles) return E_POINTER;
+STDMETHODIMP VNCFB::GetVisibleRegion(BYTE *rectangles, ULONG /* count */, ULONG * /* countCopied */)
+{
+    if (!rectangles)
+        return E_POINTER;
     *rectangles = 0;
     return S_OK;
@@ -565,10 +667,13 @@
 
 /** Stubbed */
-STDMETHODIMP VNCFB::SetVisibleRegion(BYTE *rectangles, ULONG /* count */) {
-    if (!rectangles) return E_POINTER;
-    return S_OK;
-}
-
-STDMETHODIMP VNCFB::ProcessVHWACommand(BYTE *pCommand) {
+STDMETHODIMP VNCFB::SetVisibleRegion(BYTE *rectangles, ULONG /* count */)
+{
+    if (!rectangles)
+        return E_POINTER;
+    return S_OK;
+}
+
+STDMETHODIMP VNCFB::ProcessVHWACommand(BYTE *pCommand)
+{
     return E_NOTIMPL;
 }
Index: /trunk/src/VBox/Frontends/VBoxHeadless/FramebufferVNC.h
===================================================================
--- /trunk/src/VBox/Frontends/VBoxHeadless/FramebufferVNC.h	(revision 30199)
+++ /trunk/src/VBox/Frontends/VBoxHeadless/FramebufferVNC.h	(revision 30200)
@@ -43,5 +43,6 @@
     STDMETHOD_(ULONG, Release)() {
         long cnt = ::InterlockedDecrement (&refcnt);
-        if (cnt == 0) delete this;
+        if (cnt == 0)
+            delete this;
         return cnt;
     }
@@ -52,5 +53,6 @@
 
     // public methods only for internal purposes
-    HRESULT init ();
+    HRESULT init (const char *pszName);
+    void enableAbsMouse(bool fEnable);
 
     STDMETHOD(COMGETTER(Width))(ULONG *width);
@@ -104,4 +106,6 @@
     void kbdPutCodeShift(int shift, int code, int down);
 
+    bool fAbsMouseEnabled;
+
     ULONG mWidth, mHeight;
 
Index: /trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp	(revision 30199)
+++ /trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp	(revision 30200)
@@ -81,4 +81,9 @@
 static IConsole *gConsole = NULL;
 static EventQueue *gEventQ = NULL;
+
+#ifdef VBOX_WITH_VNC
+static VNCFB *g_pFramebufferVNC;
+#endif
+
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -322,4 +327,8 @@
             }
         }
+#ifdef VBOX_WITH_VNC
+        if (g_pFramebufferVNC)
+            g_pFramebufferVNC->enableAbsMouse(supportsAbsolute);
+#endif
         return S_OK;
     }
@@ -963,16 +972,18 @@
         if (fVNCEnable)
         {
-            VNCFB *pFramebufferVNC = new VNCFB(console, uVNCPort, pszVNCPassword);
-            rc = pFramebufferVNC->init();
+            Bstr name;
+            machine->COMGETTER(Name)(name.asOutParam());
+            g_pFramebufferVNC = new VNCFB(console, uVNCPort, pszVNCPassword);
+            rc = g_pFramebufferVNC->init(name ? Utf8Str(name).raw() : "");
             if (rc != S_OK)
             {
                 LogError("Failed to load the vnc server extension, possibly due to a damaged file\n", rc);
-                delete pFramebufferVNC;
+                delete g_pFramebufferVNC;
                 break;
             }
 
             Log2(("VBoxHeadless: Registering VNC framebuffer\n"));
-            pFramebufferVNC->AddRef();
-            display->SetFramebuffer(VBOX_VIDEO_PRIMARY_SCREEN, pFramebufferVNC);
+            g_pFramebufferVNC->AddRef();
+            display->SetFramebuffer(VBOX_VIDEO_PRIMARY_SCREEN, g_pFramebufferVNC);
         }
         if (rc != S_OK)
@@ -986,5 +997,5 @@
         for (uScreenId = 0; uScreenId < cMonitors; uScreenId++)
         {
-#ifdef VBOX_FFMPEG
+# ifdef VBOX_FFMPEG
             if (fFFMPEG && uScreenId == 0)
             {
@@ -992,5 +1003,12 @@
                 continue;
             }
-#endif /* defined(VBOX_FFMPEG) */
+# endif
+# ifdef VBOX_WITH_VNC
+            if (fVNCEnable && uScreenId == 0)
+            {
+                /* Already registered. */
+                continue;
+            }
+# endif
             VRDPFramebuffer *pVRDPFramebuffer = new VRDPFramebuffer();
             if (!pVRDPFramebuffer)
