|
@@ -68,6 +68,36 @@ void *CAllocator::Reallocate(void *p, size_t nBytes) throw() {
|
|
|
void *CAllocator::Allocate(size_t nBytes) throw() { return malloc(nBytes); }
|
|
|
void CAllocator::Free(void *p) throw() { free(p); }
|
|
|
|
|
|
+//===--------------------------- BSTR Allocation --------------------------===//
|
|
|
+
|
|
|
+void SysFreeString(BSTR bstrString) {
|
|
|
+ if (bstrString)
|
|
|
+ free((void *)((uintptr_t)bstrString - sizeof(uint32_t)));
|
|
|
+}
|
|
|
+
|
|
|
+// Allocate string with length prefix
|
|
|
+// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/automat/bstr
|
|
|
+BSTR SysAllocStringLen(const OLECHAR *strIn, UINT ui) {
|
|
|
+ uint32_t *blobOut =
|
|
|
+ (uint32_t *)malloc(sizeof(uint32_t) + (ui + 1) * sizeof(OLECHAR));
|
|
|
+
|
|
|
+ if (!blobOut)
|
|
|
+ return nullptr;
|
|
|
+
|
|
|
+ // Size in bytes without trailing NULL character
|
|
|
+ blobOut[0] = ui * sizeof(OLECHAR);
|
|
|
+
|
|
|
+ BSTR strOut = (BSTR)&blobOut[1];
|
|
|
+
|
|
|
+ if (strIn)
|
|
|
+ memcpy(strOut, strIn, blobOut[0]);
|
|
|
+
|
|
|
+ // Write trailing NULL character:
|
|
|
+ strOut[ui] = 0;
|
|
|
+
|
|
|
+ return strOut;
|
|
|
+}
|
|
|
+
|
|
|
//===---------------------- Char converstion ------------------------------===//
|
|
|
|
|
|
const char *CPToLocale(uint32_t CodePage) {
|