Ejemplo n.º 1
0
BSTR WINAPI SysAllocStringLen(const OLECHAR *sz, unsigned int numChars) // FIXME - code
{
  UINT len = (numChars + 1) * sizeof(OLECHAR);
  void *p = AllocateForBSTR(len + sizeof(UINT));
  if (p == 0)
    return 0;
  memset(p,0,len + sizeof(UINT));
  *(UINT *)p = numChars * sizeof(OLECHAR); // FIXED
  void * bstr = (void *)((UINT *)p + 1);
  if (sz) memmove(bstr, sz, numChars  * sizeof(OLECHAR)); // sz does not always have "wchar_t" alignment.

  return (BSTR)bstr;
}
Ejemplo n.º 2
0
BSTR SysAllocString(const OLECHAR *sz)
{
  if (sz == 0)
    return 0;
  UINT strLen = MyStringLen(sz);
  UINT len = (strLen + 1) * sizeof(OLECHAR);
  void *p = AllocateForBSTR(len + sizeof(UINT));
  if (p == 0)
    return 0;
  *(UINT *)p = strLen;
  BSTR bstr = (BSTR)((UINT *)p + 1);
  memmove(bstr, sz, len);
  return bstr;
}
Ejemplo n.º 3
0
BSTR SysAllocStringByteLen(LPCSTR psz, UINT len)
{
  int realLen = len + sizeof(UINT) + sizeof(OLECHAR) + sizeof(OLECHAR);
  void *p = AllocateForBSTR(realLen);
  if (p == 0)
    return 0;
  *(UINT *)p = len;
  BSTR bstr = (BSTR)((UINT *)p + 1);
  memmove(bstr, psz, len);
  Byte *pb = ((Byte *)bstr) + len;
  for (int i = 0; i < sizeof(OLECHAR) * 2; i++)
    pb[i] = 0;
  return bstr;
}
Ejemplo n.º 4
0
BSTR SysAllocString(const OLECHAR *sz)
{
  if (sz == 0)
    return 0;
  UINT strLen = MyStringLen(sz);
  UINT len = (strLen + 1) * sizeof(OLECHAR);
  void *p = AllocateForBSTR(len + sizeof(UINT));
  if (p == 0)
    return 0;
  *(UINT *)p = strLen * sizeof(OLECHAR); // FIXED
  void * bstr = (void *)((UINT *)p + 1);
  memmove(bstr, sz, len); // sz does not always have "wchar_t" alignment.
  return (BSTR)bstr;
}
Ejemplo n.º 5
0
BSTR SysAllocStringLen(const OLECHAR *s, UINT len)
{
    if (len >= (k_BstrSize_Max - sizeof(OLECHAR) - sizeof(CBstrSizeType)) / sizeof(OLECHAR))
        return NULL;

    UINT size = len * sizeof(OLECHAR);
    void *p = AllocateForBSTR(size + sizeof(CBstrSizeType) + sizeof(OLECHAR));
    if (!p)
        return NULL;
    *(CBstrSizeType *)p = (CBstrSizeType)size;
    BSTR bstr = (BSTR)((CBstrSizeType *)p + 1);
    if (s)
        memcpy(bstr, s, size);
    bstr[len] = 0;
    return bstr;
}
Ejemplo n.º 6
0
BSTR SysAllocStringByteLen(LPCSTR psz, UINT len)
{
  // FIXED int realLen = len + sizeof(UINT) + 3;
  const int LEN_ADDON = sizeof(wchar_t) - 1;
  int realLen = len + sizeof(UINT) + sizeof(wchar_t) + LEN_ADDON;
  void *p = AllocateForBSTR(realLen);
  if (p == 0)
    return 0;
  *(UINT *)p = len;
  // "void *" instead of "BSTR" to avoid unaligned copy of "wchar_t" because of optimizer on Solaris
  void * bstr = (void *)((UINT *)p + 1);
  if (psz) memmove(bstr, psz, len); // psz does not always have "wchar_t" alignment.
  void *pb = (void *)(((Byte *)bstr) + len);
  memset(pb,0,sizeof(wchar_t) + LEN_ADDON);
  return (BSTR)bstr;
}
Ejemplo n.º 7
0
BSTR SysAllocStringByteLen(LPCSTR s, UINT len)
{
    /* Original SysAllocStringByteLen in Win32 maybe fills only unaligned null OLECHAR at the end.
     We provide also aligned null OLECHAR at the end. */

    if (len >= (k_BstrSize_Max - sizeof(OLECHAR) - sizeof(OLECHAR) - sizeof(CBstrSizeType)))
        return NULL;

    UINT size = (len + sizeof(OLECHAR) + sizeof(OLECHAR) - 1) & ~(sizeof(OLECHAR) - 1);
    void *p = AllocateForBSTR(size + sizeof(CBstrSizeType));
    if (!p)
        return NULL;
    *(CBstrSizeType *)p = (CBstrSizeType)len;
    BSTR bstr = (BSTR)((CBstrSizeType *)p + 1);
    if (s)
        memcpy(bstr, s, len);
    for (; len < size; len++)
        ((Byte *)bstr)[len] = 0;
    return bstr;
}