Q:

How to send C++ console params to C# DLL

I need to send two numbers entered as parameters or requested by C++ console to a library in C#.
Manually the code is:
BSTR thing_to_send = ::SysAllocString(L"10 20");
How can I create a variable of type BSTR using the values of the parameters indicated by the console or by two variables of type integer or string.
I need to concatenate the values using a space between them, for example:
string Num1 = 30;
string Num2 = 40;
string dataToSend = Num1 + " " + Num2;
or
string Num1 = argv[1];
string Num2 = argv[2];
string dataToSend 
dataToSend += Num1 + " ";
dataToSend += Num2;
How I can convert dataToSend to BSTR valid variable to send with:
HRESULT hResult = obj->GetTheThing(dataToSend, &returned_thing);?
What I have tried:
In each page that I have reviewed other types of values of origin for the transformation are indicated, with explicit values of chain like being "Cade to convert" but not with the use of variables as it is in this case
The code I need to solve is:
BSTR thing_to_send = ::SysAllocString(L"10 20");
BSTR returned_thing;
BimObjectTest_CSharp::_TheClassPtr obj(__uuidof(BimObjectTest_CSharp::TheClass));
HRESULT hResult = obj->GetTheThing(thing_to_send, &returned_thing);

the literal L "10 20" must be replaced by the parameters of the console or by two variables requested via the console, note the space between the values!
BSTR thing_to_send should contain, for example, argv[1] + " " + argv[2]!

A:

Here is a function CombineStrings, that combines two _TSTRINGs to BSTR with space between them. There is also a main function that show how to call it with console arguments.
BSTR CombineStrings(_TCHAR* arg1, _TCHAR* arg2) {
        long len1 = wcsnlen_s(arg1, 100);
        long len2 = wcsnlen_s(arg2, 100);

        BSTR result = SysAllocStringLen(NULL, len1 + len2 + 1);
        memcpy(result, arg1, len1 * sizeof(OLECHAR));
        memcpy(result + len1, L" ", 1 * sizeof(OLECHAR));
        memcpy(result + len1 + 1, arg2, len2 * sizeof(OLECHAR));

        result[len1 + len2 + 1] = NULL; // contains "firstarg<empty>secondarg"
        return result;
    }

    int _tmain(int argc, _TCHAR* argv[])
    {
        if (argc < 3) {
            // two arguments required.
            return -1;
        }

        BSTR combinedStr = CombineStrings(argv[1], argv[2]);
        BSTR returned_thing;
        HRESULT hResult = obj->GetTheThing(combinedStr, &returned_thing);

        SysFreeString(combinedStr);
        return 0;
    }

