BSTR how to make your own?

I need to associate a Linux application with a server that uses bstr data. Can I roll my own code to do bstr? I know the basics of bstr, that it has a header with a byte size minus a null terminator, and because of the header, it can contain zeros in the middle of the line and basically all the other rules that follow bstr.

I'm not sure about the byte ordering the header or more intimate details, such as passing data when pointing to the header or on the 5th byte, for example com? Does anyone know where I can get this information, or did anyone write a class like bstr for linux? Or in general, where can I find information on the details of bstr, and not just general reviews based on Microsoft libs?

thank

+3
source share
1 answer

This may be of interest to you:

Eric's Complete Guide to BSTR Semantics

EDIT: Some additional information derived from this article:

DISCLAIMER: This does not correspond to my head, and I have serious errors, up to the destruction of causality and the end of the known universe.

struct BSTR_data {
    short count;
    wchar_t[] data;
};

typedef wchar BSTR;

BSTR * AllocateBSTR(wchar * str) {
    if(str == 0) return 0;

    short len = wstrlen(str);

    BSTR_data * ret = new char[sizeof(short) + (sizeof(wchar_t) + 1) * len];

    ret->count = len;

    memcpy(ret->data, str, sizeof(wchar_t) * 2 * len);

    ret->data[len] = 0;

    return (BSTR *)(ret + sizeof(short));
}

void DeallocateBSTR(BSTR * str) {
    if(str == 0) return;

    BSTR_data * bstr = (BSTR_data*)(str - sizeof(short));

    delete bstr;
}

This should give you a good idea of ​​what is happening. Note that if cross-compatibility with Win32 is important, you need to use SysAllocString, etc. Instead of this code.

+4
source

Source: https://habr.com/ru/post/1758985/


All Articles