⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringtable.c

📁 winNT技术操作系统,国外开放的原代码和LIUX一样
💻 C
📖 第 1 页 / 共 2 页
字号:
    TRACE("%p\n", (PVOID)hStringTable);

    pSourceTable = (PSTRING_TABLE)hStringTable;
    if (pSourceTable == NULL)
    {
        ERR("Invalid hStringTable!\n");
        return (HSTRING_TABLE)NULL;
    }

    pDestinationTable = MyMalloc(sizeof(STRING_TABLE));
    if (pDestinationTable == NULL)
    {
        ERR("Cound not allocate a new string table!\n");
        return (HSTRING_TABLE)NULL;
    }

    memset(pDestinationTable, 0, sizeof(STRING_TABLE));

    pDestinationTable->pSlots = MyMalloc(sizeof(TABLE_SLOT) * pSourceTable->dwMaxSlots);
    if (pDestinationTable->pSlots == NULL)
    {
        MyFree(pDestinationTable);
        return (HSTRING_TABLE)NULL;
    }

    memset(pDestinationTable->pSlots, 0, sizeof(TABLE_SLOT) * pSourceTable->dwMaxSlots);

    pDestinationTable->dwUsedSlots = 0;
    pDestinationTable->dwMaxSlots = pSourceTable->dwMaxSlots;

    for (i = 0; i < pSourceTable->dwMaxSlots; i++)
    {
        if (pSourceTable->pSlots[i].pString != NULL)
        {
            length = (lstrlenW(pSourceTable->pSlots[i].pString) + 1) * sizeof(WCHAR);
            pDestinationTable->pSlots[i].pString = MyMalloc(length);
            if (pDestinationTable->pSlots[i].pString != NULL)
            {
                memcpy(pDestinationTable->pSlots[i].pString,
                       pSourceTable->pSlots[i].pString,
                       length);
                pDestinationTable->dwUsedSlots++;
            }

            if (pSourceTable->pSlots[i].pData != NULL)
            {
                length = pSourceTable->pSlots[i].dwSize;
                pDestinationTable->pSlots[i].pData = MyMalloc(length);
                if (pDestinationTable->pSlots[i].pData)
                {
                    memcpy(pDestinationTable->pSlots[i].pData,
                           pSourceTable->pSlots[i].pData,
                           length);
                    pDestinationTable->pSlots[i].dwSize = length;
                }
            }
        }
    }

    return (HSTRING_TABLE)pDestinationTable;
}


/**************************************************************************
 * StringTableGetExtraData [SETUPAPI.@]
 *
 * Retrieves extra data from a given string table entry.
 *
 * PARAMS
 *     hStringTable    [I] Handle to the string table
 *     dwId            [I] String ID
 *     lpExtraData     [I] Pointer a buffer that receives the extra data
 *     dwExtraDataSize [I] Size of the buffer
 *
 * RETURNS
 *     Success: TRUE
 *     Failure: FALSE
 */
BOOL WINAPI
StringTableGetExtraData(HSTRING_TABLE hStringTable,
                        DWORD dwId,
                        LPVOID lpExtraData,
                        DWORD dwExtraDataSize)
{
    PSTRING_TABLE pStringTable;

    TRACE("%p %lx %p %lu\n",
          (PVOID)hStringTable, dwId, lpExtraData, dwExtraDataSize);

    pStringTable = (PSTRING_TABLE)hStringTable;
    if (pStringTable == NULL)
    {
        ERR("Invalid hStringTable!\n");
        return FALSE;
    }

    if (dwId == 0 || dwId > pStringTable->dwMaxSlots)
    {
        ERR("Invalid Slot id!\n");
        return FALSE;
    }

    if (pStringTable->pSlots[dwId - 1].dwSize < dwExtraDataSize)
    {
        ERR("Data size is too large!\n");
        return FALSE;
    }

    memcpy(lpExtraData,
           pStringTable->pSlots[dwId - 1].pData,
           dwExtraDataSize);

    return TRUE;
}


/**************************************************************************
 * StringTableLookUpString [SETUPAPI.@]
 *
 * Searches a string table for a given string.
 *
 * PARAMS
 *     hStringTable [I] Handle to the string table
 *     lpString     [I] String to be searched for
 *     dwFlags      [I] Flags
 *                        1: case sensitive compare
 *
 * RETURNS
 *     Success: String ID
 *     Failure: -1
 */
DWORD WINAPI
StringTableLookUpString(HSTRING_TABLE hStringTable,
                        LPWSTR lpString,
                        DWORD dwFlags)
{
    PSTRING_TABLE pStringTable;
    DWORD i;

    TRACE("%p %s %lx\n", (PVOID)hStringTable, debugstr_w(lpString), dwFlags);

    pStringTable = (PSTRING_TABLE)hStringTable;
    if (pStringTable == NULL)
    {
        ERR("Invalid hStringTable!\n");
        return (DWORD)-1;
    }

    /* Search for existing string in the string table */
    for (i = 0; i < pStringTable->dwMaxSlots; i++)
    {
        if (pStringTable->pSlots[i].pString != NULL)
        {
            if (dwFlags & 1)
            {
                if (!lstrcmpW(pStringTable->pSlots[i].pString, lpString))
                    return i + 1;
            }
            else
            {
                if (!lstrcmpiW(pStringTable->pSlots[i].pString, lpString))
                    return i + 1;
            }
        }
    }

    return (DWORD)-1;
}


/**************************************************************************
 * StringTableLookUpStringEx [SETUPAPI.@]
 *
 * Searches a string table and extra data for a given string.
 *
 * PARAMS
 *     hStringTable [I] Handle to the string table
 *     lpString     [I] String to be searched for
 *     dwFlags      [I] Flags
 *                        1: case sensitive compare
 *     lpExtraData  [O] Pointer to the buffer that receives the extra data
 *     lpReserved   [I/O] Unused
 *
 * RETURNS
 *     Success: String ID
 *     Failure: -1
 */
DWORD WINAPI
StringTableLookUpStringEx(HSTRING_TABLE hStringTable,
                          LPWSTR lpString,
                          DWORD dwFlags,
                          LPVOID lpExtraData,
                          LPDWORD lpReserved)
{
    PSTRING_TABLE pStringTable;
    DWORD i;

    TRACE("%p %s %lx\n", (PVOID)hStringTable, debugstr_w(lpString), dwFlags);

    pStringTable = (PSTRING_TABLE)hStringTable;
    if (pStringTable == NULL)
    {
        ERR("Invalid hStringTable!\n");
        return (DWORD)-1;
    }

    /* Search for existing string in the string table */
    for (i = 0; i < pStringTable->dwMaxSlots; i++)
    {
        if (pStringTable->pSlots[i].pString != NULL)
        {
            if (dwFlags & 1)
            {
                if (!lstrcmpW(pStringTable->pSlots[i].pString, lpString))
                {
                    memcpy(lpExtraData,
                           pStringTable->pSlots[i].pData,
                           pStringTable->pSlots[i].dwSize);
                    *lpReserved = 0;
                    return i + 1;
                }
            }
            else
            {
                if (!lstrcmpiW(pStringTable->pSlots[i].pString, lpString))
                {
                    memcpy(lpExtraData,
                           pStringTable->pSlots[i].pData,
                           pStringTable->pSlots[i].dwSize);
                    *lpReserved = 0;
                    return i + 1;
                }
            }
        }
    }

    return (DWORD)-1;
}


/**************************************************************************
 * StringTableSetExtraData [SETUPAPI.@]
 *
 * Sets extra data for a given string table entry.
 *
 * PARAMS
 *     hStringTable    [I] Handle to the string table
 *     dwId            [I] String ID
 *     lpExtraData     [I] Pointer to the extra data
 *     dwExtraDataSize [I] Size of the extra data
 *
 * RETURNS
 *     Success: TRUE
 *     Failure: FALSE
 */
BOOL WINAPI
StringTableSetExtraData(HSTRING_TABLE hStringTable,
                        DWORD dwId,
                        LPVOID lpExtraData,
                        DWORD dwExtraDataSize)
{
    PSTRING_TABLE pStringTable;

    TRACE("%p %lx %p %lu\n",
          (PVOID)hStringTable, dwId, lpExtraData, dwExtraDataSize);

    pStringTable = (PSTRING_TABLE)hStringTable;
    if (pStringTable == NULL)
    {
        ERR("Invalid hStringTable!\n");
        return FALSE;
    }

    if (dwId == 0 || dwId > pStringTable->dwMaxSlots)
    {
        ERR("Invalid Slot id!\n");
        return FALSE;
    }

    if (pStringTable->dwMaxDataSize < dwExtraDataSize)
    {
        ERR("Data size is too large!\n");
        return FALSE;
    }

    pStringTable->pSlots[dwId - 1].pData = MyMalloc(dwExtraDataSize);
    if (pStringTable->pSlots[dwId - 1].pData == NULL)
    {
        ERR("\n");
        return FALSE;
    }

    memcpy(pStringTable->pSlots[dwId - 1].pData,
           lpExtraData,
           dwExtraDataSize);
    pStringTable->pSlots[dwId - 1].dwSize = dwExtraDataSize;

    return TRUE;
}


/**************************************************************************
 * StringTableStringFromId [SETUPAPI.@]
 *
 * Returns a pointer to a string for the given string ID.
 *
 * PARAMS
 *     hStringTable [I] Handle to the string table.
 *     dwId         [I] String ID
 *
 * RETURNS
 *     Success: Pointer to the string
 *     Failure: NULL
 */
LPWSTR WINAPI
StringTableStringFromId(HSTRING_TABLE hStringTable,
                        DWORD dwId)
{
    PSTRING_TABLE pStringTable;

    TRACE("%p %lx\n", (PVOID)hStringTable, dwId);

    pStringTable = (PSTRING_TABLE)hStringTable;
    if (pStringTable == NULL)
    {
        ERR("Invalid hStringTable!\n");
        return NULL;
    }

    if (dwId == 0 || dwId > pStringTable->dwMaxSlots)
        return empty;

    return pStringTable->pSlots[dwId - 1].pString;
}


/**************************************************************************
 * StringTableStringFromIdEx [SETUPAPI.@]
 *
 * Returns a string for the given string ID.
 *
 * PARAMS
 *     hStringTable [I] Handle to the string table
 *     dwId         [I] String ID
 *     lpBuffer     [I] Pointer to string buffer
 *     lpBufferSize [I/O] Pointer to the size of the string buffer
 *
 * RETURNS
 *     Success: TRUE
 *     Failure: FALSE
 */
BOOL WINAPI
StringTableStringFromIdEx(HSTRING_TABLE hStringTable,
                          DWORD dwId,
                          LPWSTR lpBuffer,
                          LPDWORD lpBufferLength)
{
    PSTRING_TABLE pStringTable;
    DWORD dwLength;
    BOOL bResult = FALSE;

    TRACE("%p %lx %p %p\n",
          (PVOID)hStringTable, dwId, lpBuffer, lpBufferLength);

    pStringTable = (PSTRING_TABLE)hStringTable;
    if (pStringTable == NULL)
    {
        ERR("Invalid hStringTable!\n");
        *lpBufferLength = 0;
        return FALSE;
    }

    if (dwId == 0 || dwId > pStringTable->dwMaxSlots ||
        pStringTable->pSlots[dwId - 1].pString == NULL)
    {
        WARN("Invalid string ID!\n");
        *lpBufferLength = 0;
        return FALSE;
    }

    dwLength = (lstrlenW(pStringTable->pSlots[dwId - 1].pString) + 1) * sizeof(WCHAR);
    if (dwLength <= *lpBufferLength)
    {
        lstrcpyW(lpBuffer, pStringTable->pSlots[dwId - 1].pString);
        bResult = TRUE;
    }

    *lpBufferLength = dwLength;

    return bResult;
}


/**************************************************************************
 * StringTableTrim [SETUPAPI.@]
 *
 * ...
 *
 * PARAMS
 *     hStringTable [I] Handle to the string table
 *
 * RETURNS
 *     None
 */
VOID WINAPI
StringTableTrim(HSTRING_TABLE hStringTable)
{
    FIXME("%p\n", (PVOID)hStringTable);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -