VirtualBox

Changeset 46745 in vbox for trunk/src/VBox/Additions/WINNT


Ignore:
Timestamp:
Jun 23, 2013 6:22:49 PM (12 years ago)
Author:
vboxsync
Message:

VBoxDrvInst.cpp: changed loadInstalledDll to fail of GetModuleFileName fails. Also converted it to unicode since we cannot make the same assumption regarding user controlled install/temp dirs as we about the microsoft dictated c:\windows\system32 dir.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/Installer/VBoxDrvInst.cpp

    r46710 r46745  
    136136 *
    137137 * @returns Module handle or NULL
    138  * @param   pszName             The DLL name.
     138 * @param   pwszName            The DLL name.
    139139 */
    140 static HMODULE loadInstalledDll(const char *pszName)
    141 {
    142     char   szPath[MAX_PATH];
    143     UINT   cchPath = GetModuleFileNameA(NULL, szPath, sizeof(szPath));
    144     size_t cbName = strlen(pszName) + 1;
    145     if (cchPath && cchPath <= sizeof(szPath))
    146     {
    147         char *pszSlashFile = strrchr(szPath, '\\');
    148         if (pszSlashFile)
    149             cchPath = pszSlashFile - szPath;
    150     }
    151     if (cchPath + 1 + cbName > sizeof(szPath))
     140static HMODULE loadInstalledDll(const wchar_t *pwszName)
     141{
     142    /* Get the process image path. */
     143    WCHAR  wszPath[MAX_PATH];
     144    UINT   cwcPath = GetModuleFileNameW(NULL, wszPath, MAX_PATH);
     145    if (!cwcPath || cwcPath >= MAX_PATH)
    152146        return NULL;
    153     szPath[cchPath] = '\\';
    154     memcpy(&szPath[cchPath + 1], pszName, cbName);
    155     return LoadLibraryA(szPath);
     147
     148    /* Drop the image filename. */
     149    UINT   off = cwcPath - 1;
     150    for (;;)
     151    {
     152        if (   wszPath[off] == '\\'
     153            || wszPath[off] == '/'
     154            || wszPath[off] == ':')
     155        {
     156            wszPath[off] = '\0';
     157            cwcPath = off;
     158            break;
     159        }
     160        if (!off--)
     161            return NULL; /* No path? Shouldn't ever happen! */
     162    }
     163
     164    /* Check if there is room in the buffer to construct the desired name. */
     165    size_t cwcName = 0;
     166    while (pwszName[cwcName])
     167        cwcName++;
     168    if (cwcPath + 1 + cwcName + 1 > MAX_PATH)
     169        return NULL;
     170
     171    wszPath[cwcPath] = '\\';
     172    memcpy(&wszPath[cwcPath + 1], pwszName, (cwcName + 1) * sizeof(wszPath[0]));
     173    return LoadLibraryW(wszPath);
    156174}
    157175
     
    170188{
    171189    HRESULT hr = S_OK;
    172     HMODULE hDIFxAPI = loadInstalledDll("DIFxAPI.dll");
     190    HMODULE hDIFxAPI = loadInstalledDll(L"DIFxAPI.dll");
    173191    if (NULL == hDIFxAPI)
    174192    {
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