VirtualBox

Changeset 3102 in vbox


Ignore:
Timestamp:
Jun 13, 2007 4:15:06 PM (18 years ago)
Author:
vboxsync
Message:

Store VM-Console window’s HWND handler feature implemented (secunet request):

This feature is used to store HWND handler of the VM’s main-window into the Named Virtual Shared Memory segment with VBoxQt-{machine-id} name allowing other application get accessing the main VM console window.

Every time VM window is started, the required information (HWND) is stored into the NVSM segment in the form of VBoxQtInfo structure:
struct VBoxQtInfo
{

uint32_t version; /* Version of the structure, currently 1 */
HWND hwndWin; /* HWND Descriptor */

};
Other application can get access to this segment by segment’s name to use the stored information.
The NVSM segment will be erased by the OS only in case of all of the opened handlers to it are closed.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleWnd.h

    r2981 r3102  
    111111    void updateAppearanceOf (int element);
    112112
     113#ifdef Q_WS_WIN
     114    void storeHwndDescriptor();
     115    void cleanHwndDescriptor();
     116    HANDLE mMapFile;
     117    LPCTSTR mBuf;
     118#endif
     119
    113120private slots:
    114121
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp

    r3006 r3102  
    699699    csession = session;
    700700
     701#ifdef Q_WS_WIN
     702    /* Store HWND descriptor into named virtual shared memory segment. */
     703    storeHwndDescriptor();
     704#endif
     705
    701706    if (!centralWidget())
    702707    {
     
    9961001        return;
    9971002    }
     1003
     1004#ifdef Q_WS_WIN
     1005    /* Closes the handlers to the stored NVSM segment to let the system free it. */
     1006    cleanHwndDescriptor();
     1007#endif
    9981008
    9991009    idle_timer->stop();
     
    17271737}
    17281738
     1739#ifdef Q_WS_WIN
     1740/* This function stores the current VM console window HWND handler to the
     1741 * named virtual shared memory segment with VBoxQt-{machine-uuid} name
     1742 * allowing other application get accessing this VM console window. */
     1743void VBoxConsoleWnd::storeHwndDescriptor()
     1744{
     1745    QString machineId = csession.GetMachine().GetId().toString();
     1746    QString segmentName = QString ("VBoxQt-%1").arg (machineId);
     1747
     1748    /* Structure for storing HWND information */
     1749    struct VBoxQtInfo
     1750    {
     1751        VBoxQtInfo (uint32_t aVersion, HWND aHwnd)
     1752            : version (aVersion), hwndWin (aHwnd) {}
     1753        uint32_t version; /* Version of the structure, currently 1 */
     1754        HWND     hwndWin; /* HWND Descriptor */
     1755    } info (1, winId());
     1756
     1757    /* Open NVSM handle */
     1758    mMapFile = CreateFileMapping (INVALID_HANDLE_VALUE,   // use paging file
     1759                                  NULL,                   // default security
     1760                                  PAGE_READWRITE,         // read/write access
     1761                                  0,                      // max. object size
     1762                                  sizeof (info),          // buffer size
     1763                         (LPCWSTR)segmentName.unicode()); // name of mapping object
     1764    if (mMapFile == NULL) return;
     1765
     1766    mBuf = (LPTSTR) MapViewOfFile (mMapFile,              // handle to map object
     1767                                   FILE_MAP_ALL_ACCESS,   // read/write permission
     1768                                   0,
     1769                                   0,
     1770                                   sizeof (info));
     1771    if (mBuf == NULL) return;
     1772
     1773    CopyMemory ((PVOID)mBuf, (void*)&info, sizeof (info));
     1774}
     1775
     1776/* This function closes any handlers pointed to allocated named virtual
     1777 * shared memory segment with this dialog's HWND handler. */
     1778void VBoxConsoleWnd::cleanHwndDescriptor()
     1779{
     1780    /* Freeing resources */
     1781    if (mBuf != NULL)
     1782        UnmapViewOfFile (mBuf);
     1783    if (mMapFile != NULL)
     1784        CloseHandle (mMapFile);
     1785}
     1786#endif
     1787
     1788
    17291789//
    17301790// Private slots
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette