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]!
c# c++
|
show 5 more comments
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]!
c# c++
BSTR in c++ is really a byte terminates with a ''. Strings in c# are two byte objects with a private property which indicates if the character is one or two bytes. Encoding method will set the private property indicating the number of bytes. BSTR uses Encoding.UTF8 which makes all the characters one byte.
– jdweng
Nov 15 '18 at 14:38
I really know what I need, what I have asked is how to achieve it?
– user1380697
Nov 15 '18 at 14:47
From your question I conclude that you have C# library that takes BSTR arguments and in your C++ client app you want to construct BSTR from command line arguments. Is this correct? C# libraries usually do not take BSTR arguments, unless they export COM objects, which is of course possible. Anyway we can reduce your question to "How to construct BSTR from two strings?" or "How to append to BSTR"? Is this correct?
– devdimi
Nov 15 '18 at 14:58
Google "c++ convert std::string to bstr". Lotsa hits, many on SO.
– Hans Passant
Nov 15 '18 at 14:58
@ devdimi, I am sending parameters from a console in C ++ to a library in C #, if I use a literal like the one indicated in the question, that is, something like L "10 20", the conversion works but if I try it with a string variable , it does not work.
– user1380697
Nov 15 '18 at 15:01
|
show 5 more comments
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]!
c# c++
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]!
c# c++
c# c++
edited Nov 15 '18 at 15:28
asked Nov 15 '18 at 14:31
user1380697
BSTR in c++ is really a byte terminates with a ''. Strings in c# are two byte objects with a private property which indicates if the character is one or two bytes. Encoding method will set the private property indicating the number of bytes. BSTR uses Encoding.UTF8 which makes all the characters one byte.
– jdweng
Nov 15 '18 at 14:38
I really know what I need, what I have asked is how to achieve it?
– user1380697
Nov 15 '18 at 14:47
From your question I conclude that you have C# library that takes BSTR arguments and in your C++ client app you want to construct BSTR from command line arguments. Is this correct? C# libraries usually do not take BSTR arguments, unless they export COM objects, which is of course possible. Anyway we can reduce your question to "How to construct BSTR from two strings?" or "How to append to BSTR"? Is this correct?
– devdimi
Nov 15 '18 at 14:58
Google "c++ convert std::string to bstr". Lotsa hits, many on SO.
– Hans Passant
Nov 15 '18 at 14:58
@ devdimi, I am sending parameters from a console in C ++ to a library in C #, if I use a literal like the one indicated in the question, that is, something like L "10 20", the conversion works but if I try it with a string variable , it does not work.
– user1380697
Nov 15 '18 at 15:01
|
show 5 more comments
BSTR in c++ is really a byte terminates with a ''. Strings in c# are two byte objects with a private property which indicates if the character is one or two bytes. Encoding method will set the private property indicating the number of bytes. BSTR uses Encoding.UTF8 which makes all the characters one byte.
– jdweng
Nov 15 '18 at 14:38
I really know what I need, what I have asked is how to achieve it?
– user1380697
Nov 15 '18 at 14:47
From your question I conclude that you have C# library that takes BSTR arguments and in your C++ client app you want to construct BSTR from command line arguments. Is this correct? C# libraries usually do not take BSTR arguments, unless they export COM objects, which is of course possible. Anyway we can reduce your question to "How to construct BSTR from two strings?" or "How to append to BSTR"? Is this correct?
– devdimi
Nov 15 '18 at 14:58
Google "c++ convert std::string to bstr". Lotsa hits, many on SO.
– Hans Passant
Nov 15 '18 at 14:58
@ devdimi, I am sending parameters from a console in C ++ to a library in C #, if I use a literal like the one indicated in the question, that is, something like L "10 20", the conversion works but if I try it with a string variable , it does not work.
– user1380697
Nov 15 '18 at 15:01
BSTR in c++ is really a byte terminates with a ''. Strings in c# are two byte objects with a private property which indicates if the character is one or two bytes. Encoding method will set the private property indicating the number of bytes. BSTR uses Encoding.UTF8 which makes all the characters one byte.
– jdweng
Nov 15 '18 at 14:38
BSTR in c++ is really a byte terminates with a ''. Strings in c# are two byte objects with a private property which indicates if the character is one or two bytes. Encoding method will set the private property indicating the number of bytes. BSTR uses Encoding.UTF8 which makes all the characters one byte.
– jdweng
Nov 15 '18 at 14:38
I really know what I need, what I have asked is how to achieve it?
– user1380697
Nov 15 '18 at 14:47
I really know what I need, what I have asked is how to achieve it?
– user1380697
Nov 15 '18 at 14:47
From your question I conclude that you have C# library that takes BSTR arguments and in your C++ client app you want to construct BSTR from command line arguments. Is this correct? C# libraries usually do not take BSTR arguments, unless they export COM objects, which is of course possible. Anyway we can reduce your question to "How to construct BSTR from two strings?" or "How to append to BSTR"? Is this correct?
– devdimi
Nov 15 '18 at 14:58
From your question I conclude that you have C# library that takes BSTR arguments and in your C++ client app you want to construct BSTR from command line arguments. Is this correct? C# libraries usually do not take BSTR arguments, unless they export COM objects, which is of course possible. Anyway we can reduce your question to "How to construct BSTR from two strings?" or "How to append to BSTR"? Is this correct?
– devdimi
Nov 15 '18 at 14:58
Google "c++ convert std::string to bstr". Lotsa hits, many on SO.
– Hans Passant
Nov 15 '18 at 14:58
Google "c++ convert std::string to bstr". Lotsa hits, many on SO.
– Hans Passant
Nov 15 '18 at 14:58
@ devdimi, I am sending parameters from a console in C ++ to a library in C #, if I use a literal like the one indicated in the question, that is, something like L "10 20", the conversion works but if I try it with a string variable , it does not work.
– user1380697
Nov 15 '18 at 15:01
@ devdimi, I am sending parameters from a console in C ++ to a library in C #, if I use a literal like the one indicated in the question, that is, something like L "10 20", the conversion works but if I try it with a string variable , it does not work.
– user1380697
Nov 15 '18 at 15:01
|
show 5 more comments
1 Answer
1
active
oldest
votes
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;
}
THe line BSTR str1 = SysAllocString(<your first argument here>) show a error if I replace the <your first argument here> with a string variable, this work with literals only
– user1380697
Nov 15 '18 at 14:58
I have edited the answer with correct, tested code.
– devdimi
Nov 15 '18 at 15:07
Your idea is good, I put the code I need to fix, can you check that!
– user1380697
Nov 15 '18 at 15:23
ok I have capsuled the code to combine the string in a function that can be called with console arguments
– devdimi
Nov 15 '18 at 15:40
It works perfect, you saved me the weekend, thank you very much
– user1380697
Nov 15 '18 at 15:46
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321702%2fhow-to-send-c-console-params-to-c-sharp-dll%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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;
}
THe line BSTR str1 = SysAllocString(<your first argument here>) show a error if I replace the <your first argument here> with a string variable, this work with literals only
– user1380697
Nov 15 '18 at 14:58
I have edited the answer with correct, tested code.
– devdimi
Nov 15 '18 at 15:07
Your idea is good, I put the code I need to fix, can you check that!
– user1380697
Nov 15 '18 at 15:23
ok I have capsuled the code to combine the string in a function that can be called with console arguments
– devdimi
Nov 15 '18 at 15:40
It works perfect, you saved me the weekend, thank you very much
– user1380697
Nov 15 '18 at 15:46
add a comment |
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;
}
THe line BSTR str1 = SysAllocString(<your first argument here>) show a error if I replace the <your first argument here> with a string variable, this work with literals only
– user1380697
Nov 15 '18 at 14:58
I have edited the answer with correct, tested code.
– devdimi
Nov 15 '18 at 15:07
Your idea is good, I put the code I need to fix, can you check that!
– user1380697
Nov 15 '18 at 15:23
ok I have capsuled the code to combine the string in a function that can be called with console arguments
– devdimi
Nov 15 '18 at 15:40
It works perfect, you saved me the weekend, thank you very much
– user1380697
Nov 15 '18 at 15:46
add a comment |
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;
}
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;
}
edited Nov 15 '18 at 15:39
answered Nov 15 '18 at 14:47
devdimidevdimi
2,2211716
2,2211716
THe line BSTR str1 = SysAllocString(<your first argument here>) show a error if I replace the <your first argument here> with a string variable, this work with literals only
– user1380697
Nov 15 '18 at 14:58
I have edited the answer with correct, tested code.
– devdimi
Nov 15 '18 at 15:07
Your idea is good, I put the code I need to fix, can you check that!
– user1380697
Nov 15 '18 at 15:23
ok I have capsuled the code to combine the string in a function that can be called with console arguments
– devdimi
Nov 15 '18 at 15:40
It works perfect, you saved me the weekend, thank you very much
– user1380697
Nov 15 '18 at 15:46
add a comment |
THe line BSTR str1 = SysAllocString(<your first argument here>) show a error if I replace the <your first argument here> with a string variable, this work with literals only
– user1380697
Nov 15 '18 at 14:58
I have edited the answer with correct, tested code.
– devdimi
Nov 15 '18 at 15:07
Your idea is good, I put the code I need to fix, can you check that!
– user1380697
Nov 15 '18 at 15:23
ok I have capsuled the code to combine the string in a function that can be called with console arguments
– devdimi
Nov 15 '18 at 15:40
It works perfect, you saved me the weekend, thank you very much
– user1380697
Nov 15 '18 at 15:46
THe line BSTR str1 = SysAllocString(<your first argument here>) show a error if I replace the <your first argument here> with a string variable, this work with literals only
– user1380697
Nov 15 '18 at 14:58
THe line BSTR str1 = SysAllocString(<your first argument here>) show a error if I replace the <your first argument here> with a string variable, this work with literals only
– user1380697
Nov 15 '18 at 14:58
I have edited the answer with correct, tested code.
– devdimi
Nov 15 '18 at 15:07
I have edited the answer with correct, tested code.
– devdimi
Nov 15 '18 at 15:07
Your idea is good, I put the code I need to fix, can you check that!
– user1380697
Nov 15 '18 at 15:23
Your idea is good, I put the code I need to fix, can you check that!
– user1380697
Nov 15 '18 at 15:23
ok I have capsuled the code to combine the string in a function that can be called with console arguments
– devdimi
Nov 15 '18 at 15:40
ok I have capsuled the code to combine the string in a function that can be called with console arguments
– devdimi
Nov 15 '18 at 15:40
It works perfect, you saved me the weekend, thank you very much
– user1380697
Nov 15 '18 at 15:46
It works perfect, you saved me the weekend, thank you very much
– user1380697
Nov 15 '18 at 15:46
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321702%2fhow-to-send-c-console-params-to-c-sharp-dll%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
BSTR in c++ is really a byte terminates with a ''. Strings in c# are two byte objects with a private property which indicates if the character is one or two bytes. Encoding method will set the private property indicating the number of bytes. BSTR uses Encoding.UTF8 which makes all the characters one byte.
– jdweng
Nov 15 '18 at 14:38
I really know what I need, what I have asked is how to achieve it?
– user1380697
Nov 15 '18 at 14:47
From your question I conclude that you have C# library that takes BSTR arguments and in your C++ client app you want to construct BSTR from command line arguments. Is this correct? C# libraries usually do not take BSTR arguments, unless they export COM objects, which is of course possible. Anyway we can reduce your question to "How to construct BSTR from two strings?" or "How to append to BSTR"? Is this correct?
– devdimi
Nov 15 '18 at 14:58
Google "c++ convert std::string to bstr". Lotsa hits, many on SO.
– Hans Passant
Nov 15 '18 at 14:58
@ devdimi, I am sending parameters from a console in C ++ to a library in C #, if I use a literal like the one indicated in the question, that is, something like L "10 20", the conversion works but if I try it with a string variable , it does not work.
– user1380697
Nov 15 '18 at 15:01