ReactOS  0.4.15-dev-2103-g9dff498
tools.c File Reference
#include "precomp.h"
Include dependency graph for tools.c:

Go to the source code of this file.



Takes an array of Unicode strings and fills an output buffer with these strings at the end and pointers to each string at specific offsets. Useful helper for functions that copy an information structure including strings into a given buffer (like PRINTER_INFO_1).

pSourceThe array of Unicode strings to copy. Needs to have at least as many elements as the DestOffsets array.
pDestPointer to the beginning of the output buffer. The caller is responsible for verifying that this buffer is large enough to hold all strings and pointers.
DestOffsetsArray of byte offsets in the output buffer. For each element of DestOffsets, the function will copy the address of the corresponding copied string of pSource to this location in the output buffer. If a string in pSource is NULL, the function will set the pointer address to NULL in the output buffer. Use macros like FIELD_OFFSET to calculate the offsets for this array. The last element of the array must have the value MAXDWORD to let the function detect the end of the array.
pEndPointer to the end of the output buffer. That means the first element outside of the buffer given in pDest.
Returns a pointer to the beginning of the strings in pDest. The strings are copied in reverse order, so this pointer will point to the last copied string of pSource.
PBYTE WINAPI PackStrings (PCWSTR *pSource, PBYTE pDest, const DWORD *DestOffsets, PBYTE pEnd)

Function Documentation

◆ PackStrings()

PBYTE WINAPI PackStrings ( PCWSTR pSource,
PBYTE  pDest,
const DWORD DestOffsets,
PBYTE  pEnd 

Definition at line 39 of file tools.c.

40 {
41  DWORD cbString;
42  ULONG_PTR StringAddress;
44  // Loop until we reach an element with offset set to MAXDWORD.
45  while (*DestOffsets != MAXDWORD)
46  {
47  StringAddress = 0;
49  if (*pSource)
50  {
51  // Determine the length of the source string.
52  cbString = (wcslen(*pSource) + 1) * sizeof(WCHAR);
54  // Copy it before the last string.
55  pEnd -= cbString;
56  StringAddress = (ULONG_PTR)pEnd;
57  CopyMemory(pEnd, *pSource, cbString);
58  }
60  // Copy the address of the copied string to the location given by the offset.
61  CopyMemory(&pDest[*DestOffsets], &StringAddress, sizeof(ULONG_PTR));
63  // Advance to the next source string and destination offset.
64  pSource++;
65  DestOffsets++;
66  }
68  // pEnd is now at the last string we copied. Return this value as a pointer to the beginning of all strings in the output buffer.
69  return pEnd;
70 }
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define MAXDWORD
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CopyMemory
Definition: winbase.h:1662
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ULONG_PTR
Definition: config.h:101
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by _DumpLevel1PrintProviderInformation(), _LocalGetFormLevel1(), _LocalGetFormLevel2(), _LocalGetJobLevel1(), _LocalGetJobLevel2(), _LocalGetMonitorLevel1(), _LocalGetMonitorLevel2(), _LocalGetPrinterDriverLevel1(), _LocalGetPrinterDriverLevel2(), _LocalGetPrinterDriverLevel3(), _LocalGetPrinterDriverLevel4(), _LocalGetPrinterDriverLevel5(), _LocalGetPrinterDriverLevel6(), _LocalGetPrinterDriverLevel8(), _LocalGetPrinterLevel0(), _LocalGetPrinterLevel1(), _LocalGetPrinterLevel2(), _LocalGetPrinterLevel4(), _LocalGetPrinterLevel5(), _LocalmonGetPortLevel1(), _LocalmonGetPortLevel2(), EnumPrintProcessorDatatypesW(), and START_TEST().