ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

stringtable.c
Go to the documentation of this file.
00001 /*
00002  * Setupapi string table functions
00003  *
00004  * Copyright 2005 Eric Kohl
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include "setupapi_private.h"
00022 
00023 #define TABLE_DEFAULT_SIZE 256
00024 
00025 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
00026 
00027 typedef struct _TABLE_SLOT
00028 {
00029     LPWSTR pString;
00030     LPVOID pData;
00031     DWORD dwSize;
00032 } TABLE_SLOT, *PTABLE_SLOT;
00033 
00034 typedef struct _STRING_TABLE
00035 {
00036     PTABLE_SLOT pSlots;
00037     DWORD dwUsedSlots;
00038     DWORD dwMaxSlots;
00039     DWORD dwMaxDataSize;
00040 } STRING_TABLE, *PSTRING_TABLE;
00041 
00042 
00043 /**************************************************************************
00044  * pSetupStringTableInitialize [SETUPAPI.@]
00045  *
00046  * Creates a new string table and initializes it.
00047  *
00048  * PARAMS
00049  *     None
00050  *
00051  * RETURNS
00052  *     Success: Handle to the string table
00053  *     Failure: NULL
00054  */
00055 HSTRING_TABLE WINAPI
00056 pSetupStringTableInitialize(VOID)
00057 {
00058     PSTRING_TABLE pStringTable;
00059 
00060     TRACE("\n");
00061 
00062     pStringTable = MyMalloc(sizeof(STRING_TABLE));
00063     if (pStringTable == NULL)
00064     {
00065         ERR("Invalid hStringTable!\n");
00066         return NULL;
00067     }
00068 
00069     memset(pStringTable, 0, sizeof(STRING_TABLE));
00070 
00071     pStringTable->pSlots = MyMalloc(sizeof(TABLE_SLOT) * TABLE_DEFAULT_SIZE);
00072     if (pStringTable->pSlots == NULL)
00073     {
00074         MyFree(pStringTable);
00075         return NULL;
00076     }
00077 
00078     memset(pStringTable->pSlots, 0, sizeof(TABLE_SLOT) * TABLE_DEFAULT_SIZE);
00079 
00080     pStringTable->dwUsedSlots = 0;
00081     pStringTable->dwMaxSlots = TABLE_DEFAULT_SIZE;
00082     pStringTable->dwMaxDataSize = 0;
00083 
00084     TRACE("Done\n");
00085 
00086     return (HSTRING_TABLE)pStringTable;
00087 }
00088 
00089 
00090 /**************************************************************************
00091  * pSetupStringTableInitializeEx [SETUPAPI.@]
00092  *
00093  * Creates a new string table and initializes it.
00094  *
00095  * PARAMS
00096  *     dwMaxExtraDataSize [I] Maximum extra data size
00097  *     dwReserved         [I] Unused
00098  *
00099  * RETURNS
00100  *     Success: Handle to the string table
00101  *     Failure: NULL
00102  */
00103 HSTRING_TABLE WINAPI
00104 pSetupStringTableInitializeEx(DWORD dwMaxExtraDataSize,
00105                               DWORD dwReserved)
00106 {
00107     PSTRING_TABLE pStringTable;
00108 
00109     TRACE("\n");
00110 
00111     pStringTable = MyMalloc(sizeof(STRING_TABLE));
00112     if (pStringTable == NULL) return NULL;
00113 
00114     memset(pStringTable, 0, sizeof(STRING_TABLE));
00115 
00116     pStringTable->pSlots = MyMalloc(sizeof(TABLE_SLOT) * TABLE_DEFAULT_SIZE);
00117     if (pStringTable->pSlots == NULL)
00118     {
00119         MyFree(pStringTable);
00120         return NULL;
00121     }
00122 
00123     memset(pStringTable->pSlots, 0, sizeof(TABLE_SLOT) * TABLE_DEFAULT_SIZE);
00124 
00125     pStringTable->dwUsedSlots = 0;
00126     pStringTable->dwMaxSlots = TABLE_DEFAULT_SIZE;
00127     pStringTable->dwMaxDataSize = dwMaxExtraDataSize;
00128 
00129     TRACE("Done\n");
00130 
00131     return (HSTRING_TABLE)pStringTable;
00132 }
00133 
00134 
00135 /**************************************************************************
00136  * pSetupStringTableDestroy [SETUPAPI.@]
00137  *
00138  * Destroys a string table.
00139  *
00140  * PARAMS
00141  *     hStringTable [I] Handle to the string table to be destroyed
00142  *
00143  * RETURNS
00144  *     None
00145  */
00146 VOID WINAPI
00147 pSetupStringTableDestroy(HSTRING_TABLE hStringTable)
00148 {
00149     PSTRING_TABLE pStringTable;
00150     DWORD i;
00151 
00152     TRACE("%p\n", hStringTable);
00153 
00154     pStringTable = (PSTRING_TABLE)hStringTable;
00155     if (pStringTable == NULL)
00156         return;
00157 
00158     if (pStringTable->pSlots != NULL)
00159     {
00160         for (i = 0; i < pStringTable->dwMaxSlots; i++)
00161         {
00162             MyFree(pStringTable->pSlots[i].pString);
00163             pStringTable->pSlots[i].pString = NULL;
00164 
00165             MyFree(pStringTable->pSlots[i].pData);
00166             pStringTable->pSlots[i].pData = NULL;
00167             pStringTable->pSlots[i].dwSize = 0;
00168         }
00169 
00170         MyFree(pStringTable->pSlots);
00171     }
00172 
00173     MyFree(pStringTable);
00174 }
00175 
00176 
00177 /**************************************************************************
00178  * pSetupStringTableAddString [SETUPAPI.@]
00179  *
00180  * Adds a new string to the string table.
00181  *
00182  * PARAMS
00183  *     hStringTable [I] Handle to the string table
00184  *     lpString     [I] String to be added to the string table
00185  *     dwFlags      [I] Flags
00186  *                        1: case sensitive compare
00187  *
00188  * RETURNS
00189  *     Success: String ID
00190  *     Failure: -1
00191  *
00192  * NOTES
00193  *     If the given string already exists in the string table it will not
00194  *     be added again. The ID of the existing string will be returned in
00195  *     this case.
00196  */
00197 DWORD WINAPI
00198 pSetupStringTableAddString(HSTRING_TABLE hStringTable,
00199                            LPWSTR lpString,
00200                            DWORD dwFlags)
00201 {
00202     PSTRING_TABLE pStringTable;
00203     DWORD i;
00204 
00205     TRACE("%p %s %x\n", hStringTable, debugstr_w(lpString), dwFlags);
00206 
00207     pStringTable = (PSTRING_TABLE)hStringTable;
00208     if (pStringTable == NULL)
00209     {
00210         ERR("Invalid hStringTable!\n");
00211         return (DWORD)-1;
00212     }
00213 
00214     /* Search for existing string in the string table */
00215     for (i = 0; i < pStringTable->dwMaxSlots; i++)
00216     {
00217         if (pStringTable->pSlots[i].pString != NULL)
00218         {
00219             if (dwFlags & 1)
00220             {
00221                 if (!lstrcmpW(pStringTable->pSlots[i].pString, lpString))
00222                 {
00223                     return i + 1;
00224                 }
00225             }
00226             else
00227             {
00228                 if (!lstrcmpiW(pStringTable->pSlots[i].pString, lpString))
00229                 {
00230                     return i + 1;
00231                 }
00232             }
00233         }
00234     }
00235 
00236     /* Check for filled slot table */
00237     if (pStringTable->dwUsedSlots == pStringTable->dwMaxSlots)
00238     {
00239         PTABLE_SLOT pNewSlots;
00240         DWORD dwNewMaxSlots;
00241 
00242         /* FIXME: not thread safe */
00243         dwNewMaxSlots = pStringTable->dwMaxSlots * 2;
00244         pNewSlots = MyMalloc(sizeof(TABLE_SLOT) * dwNewMaxSlots);
00245         if (pNewSlots == NULL)
00246             return (DWORD)-1;
00247         memset(&pNewSlots[pStringTable->dwMaxSlots], 0, sizeof(TABLE_SLOT) * (dwNewMaxSlots - pStringTable->dwMaxSlots));
00248         memcpy(pNewSlots, pStringTable->pSlots, sizeof(TABLE_SLOT) * pStringTable->dwMaxSlots);
00249         pNewSlots = InterlockedExchangePointer(&pStringTable->pSlots, pNewSlots);
00250         MyFree(pNewSlots);
00251         pStringTable->dwMaxSlots = dwNewMaxSlots;
00252 
00253         return pSetupStringTableAddString(hStringTable, lpString, dwFlags);
00254     }
00255 
00256     /* Search for an empty slot */
00257     for (i = 0; i < pStringTable->dwMaxSlots; i++)
00258     {
00259         if (pStringTable->pSlots[i].pString == NULL)
00260         {
00261             pStringTable->pSlots[i].pString = MyMalloc((lstrlenW(lpString) + 1) * sizeof(WCHAR));
00262             if (pStringTable->pSlots[i].pString == NULL)
00263             {
00264                 TRACE("Couldn't allocate memory for a new string!\n");
00265                 return (DWORD)-1;
00266             }
00267 
00268             lstrcpyW(pStringTable->pSlots[i].pString, lpString);
00269 
00270             pStringTable->dwUsedSlots++;
00271 
00272             return i + 1;
00273         }
00274     }
00275 
00276     TRACE("Couldn't find an empty slot!\n");
00277 
00278     return (DWORD)-1;
00279 }
00280 
00281 
00282 /**************************************************************************
00283  * pSetupStringTableAddStringEx [SETUPAPI.@]
00284  *
00285  * Adds a new string plus extra data to the string table.
00286  *
00287  * PARAMS
00288  *     hStringTable    [I] Handle to the string table
00289  *     lpString        [I] String to be added to the string table
00290  *     dwFlags         [I] Flags
00291  *                           1: case sensitive compare
00292  *     lpExtraData     [I] Pointer to the extra data
00293  *     dwExtraDataSize [I] Size of the extra data
00294  *
00295  * RETURNS
00296  *     Success: String ID
00297  *     Failure: -1
00298  *
00299  * NOTES
00300  *     If the given string already exists in the string table it will not
00301  *     be added again. The ID of the existing string will be returned in
00302  *     this case.
00303  */
00304 DWORD WINAPI
00305 pSetupStringTableAddStringEx(HSTRING_TABLE hStringTable,
00306                              LPWSTR lpString,
00307                              DWORD dwFlags,
00308                              LPVOID lpExtraData,
00309                              DWORD dwExtraDataSize)
00310 {
00311     PSTRING_TABLE pStringTable;
00312     DWORD i;
00313 
00314     TRACE("%p %s %lx\n", (PVOID)hStringTable, debugstr_w(lpString), dwFlags);
00315 
00316     pStringTable = (PSTRING_TABLE)hStringTable;
00317     if (pStringTable == NULL)
00318     {
00319         ERR("Invalid hStringTable!\n");
00320         return (DWORD)-1;
00321     }
00322 
00323     /* Search for existing string in the string table */
00324     for (i = 0; i < pStringTable->dwMaxSlots; i++)
00325     {
00326         if (pStringTable->pSlots[i].pString != NULL)
00327         {
00328             if (dwFlags & 1)
00329             {
00330                 if (!lstrcmpW(pStringTable->pSlots[i].pString, lpString))
00331                 {
00332                     return i + 1;
00333                 }
00334             }
00335             else
00336             {
00337                 if (!lstrcmpiW(pStringTable->pSlots[i].pString, lpString))
00338                 {
00339                     return i + 1;
00340                 }
00341             }
00342         }
00343     }
00344 
00345     /* Check for filled slot table */
00346     if (pStringTable->dwUsedSlots == pStringTable->dwMaxSlots)
00347     {
00348         FIXME("Resize the string table!\n");
00349         return (DWORD)-1;
00350     }
00351 
00352     /* Search for an empty slot */
00353     for (i = 0; i < pStringTable->dwMaxSlots; i++)
00354     {
00355         if (pStringTable->pSlots[i].pString == NULL)
00356         {
00357             pStringTable->pSlots[i].pString = MyMalloc((lstrlenW(lpString) + 1) * sizeof(WCHAR));
00358             if (pStringTable->pSlots[i].pString == NULL)
00359             {
00360                 TRACE("Couldn't allocate memory for a new string!\n");
00361                 return (DWORD)-1;
00362             }
00363 
00364             lstrcpyW(pStringTable->pSlots[i].pString, lpString);
00365 
00366             pStringTable->pSlots[i].pData = MyMalloc(dwExtraDataSize);
00367             if (pStringTable->pSlots[i].pData == NULL)
00368             {
00369                 TRACE("Couldn't allocate memory for a new extra data!\n");
00370                 MyFree(pStringTable->pSlots[i].pString);
00371                 pStringTable->pSlots[i].pString = NULL;
00372                 return (DWORD)-1;
00373             }
00374 
00375             memcpy(pStringTable->pSlots[i].pData,
00376                    lpExtraData,
00377                    dwExtraDataSize);
00378             pStringTable->pSlots[i].dwSize = dwExtraDataSize;
00379 
00380             pStringTable->dwUsedSlots++;
00381 
00382             return i + 1;
00383         }
00384     }
00385 
00386     TRACE("Couldn't find an empty slot!\n");
00387 
00388     return (DWORD)-1;
00389 }
00390 
00391 
00392 /**************************************************************************
00393  * pSetupStringTableDuplicate [SETUPAPI.@]
00394  *
00395  * Duplicates a given string table.
00396  *
00397  * PARAMS
00398  *     hStringTable [I] Handle to the string table
00399  *
00400  * RETURNS
00401  *     Success: Handle to the duplicated string table
00402  *     Failure: NULL
00403  *
00404  */
00405 HSTRING_TABLE WINAPI
00406 pSetupStringTableDuplicate(HSTRING_TABLE hStringTable)
00407 {
00408     PSTRING_TABLE pSourceTable;
00409     PSTRING_TABLE pDestinationTable;
00410     DWORD i;
00411     DWORD length;
00412 
00413     TRACE("%p\n", hStringTable);
00414 
00415     pSourceTable = (PSTRING_TABLE)hStringTable;
00416     if (pSourceTable == NULL)
00417     {
00418         ERR("Invalid hStringTable!\n");
00419         return (HSTRING_TABLE)NULL;
00420     }
00421 
00422     pDestinationTable = MyMalloc(sizeof(STRING_TABLE));
00423     if (pDestinationTable == NULL)
00424     {
00425         ERR("Could not allocate a new string table!\n");
00426         return (HSTRING_TABLE)NULL;
00427     }
00428 
00429     memset(pDestinationTable, 0, sizeof(STRING_TABLE));
00430 
00431     pDestinationTable->pSlots = MyMalloc(sizeof(TABLE_SLOT) * pSourceTable->dwMaxSlots);
00432     if (pDestinationTable->pSlots == NULL)
00433     {
00434         MyFree(pDestinationTable);
00435         return (HSTRING_TABLE)NULL;
00436     }
00437 
00438     memset(pDestinationTable->pSlots, 0, sizeof(TABLE_SLOT) * pSourceTable->dwMaxSlots);
00439 
00440     pDestinationTable->dwUsedSlots = 0;
00441     pDestinationTable->dwMaxSlots = pSourceTable->dwMaxSlots;
00442 
00443     for (i = 0; i < pSourceTable->dwMaxSlots; i++)
00444     {
00445         if (pSourceTable->pSlots[i].pString != NULL)
00446         {
00447             length = (lstrlenW(pSourceTable->pSlots[i].pString) + 1) * sizeof(WCHAR);
00448             pDestinationTable->pSlots[i].pString = MyMalloc(length);
00449             if (pDestinationTable->pSlots[i].pString != NULL)
00450             {
00451                 memcpy(pDestinationTable->pSlots[i].pString,
00452                        pSourceTable->pSlots[i].pString,
00453                        length);
00454                 pDestinationTable->dwUsedSlots++;
00455             }
00456 
00457             if (pSourceTable->pSlots[i].pData != NULL)
00458             {
00459                 length = pSourceTable->pSlots[i].dwSize;
00460                 pDestinationTable->pSlots[i].pData = MyMalloc(length);
00461                 if (pDestinationTable->pSlots[i].pData)
00462                 {
00463                     memcpy(pDestinationTable->pSlots[i].pData,
00464                            pSourceTable->pSlots[i].pData,
00465                            length);
00466                     pDestinationTable->pSlots[i].dwSize = length;
00467                 }
00468             }
00469         }
00470     }
00471 
00472     return (HSTRING_TABLE)pDestinationTable;
00473 }
00474 
00475 
00476 /**************************************************************************
00477  * pSetupStringTableGetExtraData [SETUPAPI.@]
00478  *
00479  * Retrieves extra data from a given string table entry.
00480  *
00481  * PARAMS
00482  *     hStringTable    [I] Handle to the string table
00483  *     dwId            [I] String ID
00484  *     lpExtraData     [I] Pointer a buffer that receives the extra data
00485  *     dwExtraDataSize [I] Size of the buffer
00486  *
00487  * RETURNS
00488  *     Success: TRUE
00489  *     Failure: FALSE
00490  */
00491 BOOL WINAPI
00492 pSetupStringTableGetExtraData(HSTRING_TABLE hStringTable,
00493                               DWORD dwId,
00494                               LPVOID lpExtraData,
00495                               DWORD dwExtraDataSize)
00496 {
00497     PSTRING_TABLE pStringTable;
00498 
00499     TRACE("%p %x %p %u\n",
00500           hStringTable, dwId, lpExtraData, dwExtraDataSize);
00501 
00502     pStringTable = (PSTRING_TABLE)hStringTable;
00503     if (pStringTable == NULL)
00504     {
00505         ERR("Invalid hStringTable!\n");
00506         return FALSE;
00507     }
00508 
00509     if (dwId == 0 || dwId > pStringTable->dwMaxSlots)
00510     {
00511         ERR("Invalid Slot id!\n");
00512         return FALSE;
00513     }
00514 
00515     if (pStringTable->pSlots[dwId - 1].dwSize < dwExtraDataSize)
00516     {
00517         ERR("Data size is too large!\n");
00518         return FALSE;
00519     }
00520 
00521     memcpy(lpExtraData,
00522            pStringTable->pSlots[dwId - 1].pData,
00523            dwExtraDataSize);
00524 
00525     return TRUE;
00526 }
00527 
00528 
00529 /**************************************************************************
00530  * pSetupStringTableLookUpString [SETUPAPI.@]
00531  *
00532  * Searches a string table for a given string.
00533  *
00534  * PARAMS
00535  *     hStringTable [I] Handle to the string table
00536  *     lpString     [I] String to be searched for
00537  *     dwFlags      [I] Flags
00538  *                        1: case sensitive compare
00539  *
00540  * RETURNS
00541  *     Success: String ID
00542  *     Failure: -1
00543  */
00544 DWORD WINAPI
00545 pSetupStringTableLookUpString(HSTRING_TABLE hStringTable,
00546                               LPWSTR lpString,
00547                               DWORD dwFlags)
00548 {
00549     PSTRING_TABLE pStringTable;
00550     DWORD i;
00551 
00552     TRACE("%p %s %x\n", hStringTable, debugstr_w(lpString), dwFlags);
00553 
00554     pStringTable = (PSTRING_TABLE)hStringTable;
00555     if (pStringTable == NULL)
00556     {
00557         ERR("Invalid hStringTable!\n");
00558         return (DWORD)-1;
00559     }
00560 
00561     /* Search for existing string in the string table */
00562     for (i = 0; i < pStringTable->dwMaxSlots; i++)
00563     {
00564         if (pStringTable->pSlots[i].pString != NULL)
00565         {
00566             if (dwFlags & 1)
00567             {
00568                 if (!lstrcmpW(pStringTable->pSlots[i].pString, lpString))
00569                     return i + 1;
00570             }
00571             else
00572             {
00573                 if (!lstrcmpiW(pStringTable->pSlots[i].pString, lpString))
00574                     return i + 1;
00575             }
00576         }
00577     }
00578 
00579     return (DWORD)-1;
00580 }
00581 
00582 
00583 /**************************************************************************
00584  * pSetupStringTableLookUpStringEx [SETUPAPI.@]
00585  *
00586  * Searches a string table and extra data for a given string.
00587  *
00588  * PARAMS
00589  *     hStringTable [I] Handle to the string table
00590  *     lpString     [I] String to be searched for
00591  *     dwFlags      [I] Flags
00592  *                        1: case sensitive compare
00593  *     lpExtraData  [O] Pointer to the buffer that receives the extra data
00594  *     lpReserved   [I/O] Unused
00595  *
00596  * RETURNS
00597  *     Success: String ID
00598  *     Failure: -1
00599  */
00600 DWORD WINAPI
00601 pSetupStringTableLookUpStringEx(HSTRING_TABLE hStringTable,
00602                                 LPWSTR lpString,
00603                                 DWORD dwFlags,
00604                                 LPVOID lpExtraData,
00605                                 DWORD dwReserved)
00606 {
00607     PSTRING_TABLE pStringTable;
00608     DWORD i;
00609 
00610     TRACE("%p %s %x %p, %x\n", hStringTable, debugstr_w(lpString), dwFlags,
00611           lpExtraData, dwReserved);
00612 
00613     pStringTable = (PSTRING_TABLE)hStringTable;
00614     if (pStringTable == NULL)
00615     {
00616         ERR("Invalid hStringTable!\n");
00617         return ~0u;
00618     }
00619 
00620     /* Search for existing string in the string table */
00621     for (i = 0; i < pStringTable->dwMaxSlots; i++)
00622     {
00623         if (pStringTable->pSlots[i].pString != NULL)
00624         {
00625             if (dwFlags & 1)
00626             {
00627                 if (!lstrcmpW(pStringTable->pSlots[i].pString, lpString))
00628                 {
00629                     if (lpExtraData)
00630                         memcpy(lpExtraData, pStringTable->pSlots[i].pData, dwReserved);
00631                     return i + 1;
00632                 }
00633             }
00634             else
00635             {
00636                 if (!lstrcmpiW(pStringTable->pSlots[i].pString, lpString))
00637                 {
00638                     if (lpExtraData)
00639                         memcpy(lpExtraData, pStringTable->pSlots[i].pData, dwReserved);
00640                     return i + 1;
00641                 }
00642             }
00643         }
00644     }
00645     return ~0u;
00646 }
00647 
00648 
00649 /**************************************************************************
00650  * pSetupStringTableSetExtraData [SETUPAPI.@]
00651  *
00652  * Sets extra data for a given string table entry.
00653  *
00654  * PARAMS
00655  *     hStringTable    [I] Handle to the string table
00656  *     dwId            [I] String ID
00657  *     lpExtraData     [I] Pointer to the extra data
00658  *     dwExtraDataSize [I] Size of the extra data
00659  *
00660  * RETURNS
00661  *     Success: TRUE
00662  *     Failure: FALSE
00663  */
00664 BOOL WINAPI
00665 pSetupStringTableSetExtraData(HSTRING_TABLE hStringTable,
00666                               DWORD dwId,
00667                               LPVOID lpExtraData,
00668                               DWORD dwExtraDataSize)
00669 {
00670     PSTRING_TABLE pStringTable;
00671 
00672     TRACE("%p %x %p %u\n",
00673           hStringTable, dwId, lpExtraData, dwExtraDataSize);
00674 
00675     pStringTable = (PSTRING_TABLE)hStringTable;
00676     if (pStringTable == NULL)
00677     {
00678         ERR("Invalid hStringTable!\n");
00679         return FALSE;
00680     }
00681 
00682     if (dwId == 0 || dwId > pStringTable->dwMaxSlots)
00683     {
00684         ERR("Invalid Slot id!\n");
00685         return FALSE;
00686     }
00687 
00688     if (pStringTable->dwMaxDataSize < dwExtraDataSize)
00689     {
00690         ERR("Data size is too large!\n");
00691         return FALSE;
00692     }
00693 
00694     pStringTable->pSlots[dwId - 1].pData = MyMalloc(dwExtraDataSize);
00695     if (pStringTable->pSlots[dwId - 1].pData == NULL)
00696     {
00697         ERR("\n");
00698         return FALSE;
00699     }
00700 
00701     memcpy(pStringTable->pSlots[dwId - 1].pData,
00702            lpExtraData,
00703            dwExtraDataSize);
00704     pStringTable->pSlots[dwId - 1].dwSize = dwExtraDataSize;
00705 
00706     return TRUE;
00707 }
00708 
00709 
00710 /**************************************************************************
00711  * pSetupStringTableStringFromId [SETUPAPI.@]
00712  *
00713  * Returns a pointer to a string for the given string ID.
00714  *
00715  * PARAMS
00716  *     hStringTable [I] Handle to the string table.
00717  *     dwId         [I] String ID
00718  *
00719  * RETURNS
00720  *     Success: Pointer to the string
00721  *     Failure: NULL
00722  */
00723 LPWSTR WINAPI
00724 pSetupStringTableStringFromId(HSTRING_TABLE hStringTable,
00725                               DWORD dwId)
00726 {
00727     PSTRING_TABLE pStringTable;
00728     static WCHAR empty[] = {0};
00729 
00730     TRACE("%p %x\n", hStringTable, dwId);
00731 
00732     pStringTable = (PSTRING_TABLE)hStringTable;
00733     if (pStringTable == NULL)
00734     {
00735         ERR("Invalid hStringTable!\n");
00736         return NULL;
00737     }
00738 
00739     if (dwId == 0 || dwId > pStringTable->dwMaxSlots)
00740         return empty;
00741 
00742     return pStringTable->pSlots[dwId - 1].pString;
00743 }
00744 
00745 
00746 /**************************************************************************
00747  * pSetupStringTableStringFromIdEx [SETUPAPI.@]
00748  *
00749  * Returns a string for the given string ID.
00750  *
00751  * PARAMS
00752  *     hStringTable [I] Handle to the string table
00753  *     dwId         [I] String ID
00754  *     lpBuffer     [I] Pointer to string buffer
00755  *     lpBufferSize [I/O] Pointer to the size of the string buffer
00756  *
00757  * RETURNS
00758  *     Success: TRUE
00759  *     Failure: FALSE
00760  */
00761 BOOL WINAPI
00762 pSetupStringTableStringFromIdEx(HSTRING_TABLE hStringTable,
00763                                 DWORD dwId,
00764                                 LPWSTR lpBuffer,
00765                                 LPDWORD lpBufferLength)
00766 {
00767     PSTRING_TABLE pStringTable;
00768     DWORD dwLength;
00769     BOOL bResult = FALSE;
00770 
00771     TRACE("%p %x %p %p\n", hStringTable, dwId, lpBuffer, lpBufferLength);
00772 
00773     pStringTable = (PSTRING_TABLE)hStringTable;
00774     if (pStringTable == NULL)
00775     {
00776         ERR("Invalid hStringTable!\n");
00777         *lpBufferLength = 0;
00778         return FALSE;
00779     }
00780 
00781     if (dwId == 0 || dwId > pStringTable->dwMaxSlots ||
00782         pStringTable->pSlots[dwId - 1].pString == NULL)
00783     {
00784         WARN("Invalid string ID!\n");
00785         *lpBufferLength = 0;
00786         return FALSE;
00787     }
00788 
00789     dwLength = (lstrlenW(pStringTable->pSlots[dwId - 1].pString) + 1) * sizeof(WCHAR);
00790     if (dwLength <= *lpBufferLength)
00791     {
00792         lstrcpyW(lpBuffer, pStringTable->pSlots[dwId - 1].pString);
00793         bResult = TRUE;
00794     }
00795 
00796     *lpBufferLength = dwLength;
00797 
00798     return bResult;
00799 }

Generated on Sat May 26 2012 04:24:50 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.