Logo Search packages:      
Sourcecode: virtualbox-ose version File versions  Download package

BSTR SysAllocStringLen ( const OLECHAR *  pch,
unsigned int  cch 

Create a BSTR from the OLECHAR string with a given length in UCS2 characters

pch pointer to the source string
cch length of the source string in UCS2 characters
BSTR new string buffer

Definition at line 83 of file helpers.cpp.

References NULL, and OLECHAR.

Referenced by com::Bstr::alloc(), SysAllocString(), and SysReAllocStringLen().

    unsigned int bufferSize;
    unsigned int *newBuffer;
    OLECHAR *newString;

    // add the trailing UCS2 NULL
    bufferSize = cch * sizeof(OLECHAR);
    newBuffer = (unsigned int*)nsMemory::Alloc(bufferSize + sizeof(OLECHAR));
    if (!newBuffer)
        return NULL;
    // copy the string, a NULL input string is allowed
    if (pch)
        memcpy(newBuffer, pch, bufferSize);

    } else
        memset(newBuffer, 0, bufferSize);
    // make sure there is a trailing UCS2 NULL
    newString = (OLECHAR*)newBuffer;
    newString[cch] = L'\0';

    return (BSTR)newString;

Generated by  Doxygen 1.6.0   Back to index