CString results in ? when trying to assign _variant_t.bstrVal which contains russian chars
I am working on a desktop application.
I am facing this problem.
As you can see in the screenshot when this code runs it assigns Russian string to CString but its value gets corrupted.
CString csField = vField.bstrVal;
The bstrVal contains Створное O^Л.
When I assign it to CString it becomes ??s.
c++ mfc c-strings
add a comment |
I am working on a desktop application.
I am facing this problem.
As you can see in the screenshot when this code runs it assigns Russian string to CString but its value gets corrupted.
CString csField = vField.bstrVal;
The bstrVal contains Створное O^Л.
When I assign it to CString it becomes ??s.
c++ mfc c-strings
7
Educated guess: you are building an ANSI build, soCString
is a narrow string and the assignment involves Unicode to ANSI conversion. But the system codepage is not Cyrillic, so those Unicode characters are not representable in it. Ideally, switch to a Unicode build.
– Igor Tandetnik
Nov 23 '18 at 4:45
4
Go to your project settings, and add the _CSTRING_DISABLE_NARROW_WIDE_CONVERSION preprocessor symbol. Recompile. The error list will now contain a list of all potential bugs.
– IInspectable
Nov 23 '18 at 11:07
1
Looks likebstrVal
is a unicode andcsField
a narrow string. This will work only if the system codepage is Cyrillic, andbstrVal
contains only characters that do exist in the Cyrrilic ANSI codepage. Unfortunately the system codepage can be set only globally, not per application. See a related answer in the link below: stackoverflow.com/questions/49872812/…
– Constantine Georgiou
Nov 23 '18 at 12:50
add a comment |
I am working on a desktop application.
I am facing this problem.
As you can see in the screenshot when this code runs it assigns Russian string to CString but its value gets corrupted.
CString csField = vField.bstrVal;
The bstrVal contains Створное O^Л.
When I assign it to CString it becomes ??s.
c++ mfc c-strings
I am working on a desktop application.
I am facing this problem.
As you can see in the screenshot when this code runs it assigns Russian string to CString but its value gets corrupted.
CString csField = vField.bstrVal;
The bstrVal contains Створное O^Л.
When I assign it to CString it becomes ??s.
c++ mfc c-strings
c++ mfc c-strings
asked Nov 23 '18 at 4:42
Kishan VaishnavKishan Vaishnav
919
919
7
Educated guess: you are building an ANSI build, soCString
is a narrow string and the assignment involves Unicode to ANSI conversion. But the system codepage is not Cyrillic, so those Unicode characters are not representable in it. Ideally, switch to a Unicode build.
– Igor Tandetnik
Nov 23 '18 at 4:45
4
Go to your project settings, and add the _CSTRING_DISABLE_NARROW_WIDE_CONVERSION preprocessor symbol. Recompile. The error list will now contain a list of all potential bugs.
– IInspectable
Nov 23 '18 at 11:07
1
Looks likebstrVal
is a unicode andcsField
a narrow string. This will work only if the system codepage is Cyrillic, andbstrVal
contains only characters that do exist in the Cyrrilic ANSI codepage. Unfortunately the system codepage can be set only globally, not per application. See a related answer in the link below: stackoverflow.com/questions/49872812/…
– Constantine Georgiou
Nov 23 '18 at 12:50
add a comment |
7
Educated guess: you are building an ANSI build, soCString
is a narrow string and the assignment involves Unicode to ANSI conversion. But the system codepage is not Cyrillic, so those Unicode characters are not representable in it. Ideally, switch to a Unicode build.
– Igor Tandetnik
Nov 23 '18 at 4:45
4
Go to your project settings, and add the _CSTRING_DISABLE_NARROW_WIDE_CONVERSION preprocessor symbol. Recompile. The error list will now contain a list of all potential bugs.
– IInspectable
Nov 23 '18 at 11:07
1
Looks likebstrVal
is a unicode andcsField
a narrow string. This will work only if the system codepage is Cyrillic, andbstrVal
contains only characters that do exist in the Cyrrilic ANSI codepage. Unfortunately the system codepage can be set only globally, not per application. See a related answer in the link below: stackoverflow.com/questions/49872812/…
– Constantine Georgiou
Nov 23 '18 at 12:50
7
7
Educated guess: you are building an ANSI build, so
CString
is a narrow string and the assignment involves Unicode to ANSI conversion. But the system codepage is not Cyrillic, so those Unicode characters are not representable in it. Ideally, switch to a Unicode build.– Igor Tandetnik
Nov 23 '18 at 4:45
Educated guess: you are building an ANSI build, so
CString
is a narrow string and the assignment involves Unicode to ANSI conversion. But the system codepage is not Cyrillic, so those Unicode characters are not representable in it. Ideally, switch to a Unicode build.– Igor Tandetnik
Nov 23 '18 at 4:45
4
4
Go to your project settings, and add the _CSTRING_DISABLE_NARROW_WIDE_CONVERSION preprocessor symbol. Recompile. The error list will now contain a list of all potential bugs.
– IInspectable
Nov 23 '18 at 11:07
Go to your project settings, and add the _CSTRING_DISABLE_NARROW_WIDE_CONVERSION preprocessor symbol. Recompile. The error list will now contain a list of all potential bugs.
– IInspectable
Nov 23 '18 at 11:07
1
1
Looks like
bstrVal
is a unicode and csField
a narrow string. This will work only if the system codepage is Cyrillic, and bstrVal
contains only characters that do exist in the Cyrrilic ANSI codepage. Unfortunately the system codepage can be set only globally, not per application. See a related answer in the link below: stackoverflow.com/questions/49872812/…– Constantine Georgiou
Nov 23 '18 at 12:50
Looks like
bstrVal
is a unicode and csField
a narrow string. This will work only if the system codepage is Cyrillic, and bstrVal
contains only characters that do exist in the Cyrrilic ANSI codepage. Unfortunately the system codepage can be set only globally, not per application. See a related answer in the link below: stackoverflow.com/questions/49872812/…– Constantine Georgiou
Nov 23 '18 at 12:50
add a comment |
1 Answer
1
active
oldest
votes
*Remember: When this problem occurs, first check the current culture or locale.
The answer to the problem is:
There was a line in my code which was setting current culture to
Invariant culture.
The strange thing I could not understand is when I get the current locale by setLocale(LC_ALL, NULL) it was returning the same thing irrespective of my current culture was Russian or Invariant.
To solve this problem I removed that code and now it's working fine.
//Thread::CurrentThread->CurrentCulture = gcnew CultureInfo("");
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%2f53440744%2fcstring-results-in-when-trying-to-assign-variant-t-bstrval-which-contains-rus%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
*Remember: When this problem occurs, first check the current culture or locale.
The answer to the problem is:
There was a line in my code which was setting current culture to
Invariant culture.
The strange thing I could not understand is when I get the current locale by setLocale(LC_ALL, NULL) it was returning the same thing irrespective of my current culture was Russian or Invariant.
To solve this problem I removed that code and now it's working fine.
//Thread::CurrentThread->CurrentCulture = gcnew CultureInfo("");
add a comment |
*Remember: When this problem occurs, first check the current culture or locale.
The answer to the problem is:
There was a line in my code which was setting current culture to
Invariant culture.
The strange thing I could not understand is when I get the current locale by setLocale(LC_ALL, NULL) it was returning the same thing irrespective of my current culture was Russian or Invariant.
To solve this problem I removed that code and now it's working fine.
//Thread::CurrentThread->CurrentCulture = gcnew CultureInfo("");
add a comment |
*Remember: When this problem occurs, first check the current culture or locale.
The answer to the problem is:
There was a line in my code which was setting current culture to
Invariant culture.
The strange thing I could not understand is when I get the current locale by setLocale(LC_ALL, NULL) it was returning the same thing irrespective of my current culture was Russian or Invariant.
To solve this problem I removed that code and now it's working fine.
//Thread::CurrentThread->CurrentCulture = gcnew CultureInfo("");
*Remember: When this problem occurs, first check the current culture or locale.
The answer to the problem is:
There was a line in my code which was setting current culture to
Invariant culture.
The strange thing I could not understand is when I get the current locale by setLocale(LC_ALL, NULL) it was returning the same thing irrespective of my current culture was Russian or Invariant.
To solve this problem I removed that code and now it's working fine.
//Thread::CurrentThread->CurrentCulture = gcnew CultureInfo("");
answered Dec 3 '18 at 4:15
Kishan VaishnavKishan Vaishnav
919
919
add a comment |
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%2f53440744%2fcstring-results-in-when-trying-to-assign-variant-t-bstrval-which-contains-rus%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
7
Educated guess: you are building an ANSI build, so
CString
is a narrow string and the assignment involves Unicode to ANSI conversion. But the system codepage is not Cyrillic, so those Unicode characters are not representable in it. Ideally, switch to a Unicode build.– Igor Tandetnik
Nov 23 '18 at 4:45
4
Go to your project settings, and add the _CSTRING_DISABLE_NARROW_WIDE_CONVERSION preprocessor symbol. Recompile. The error list will now contain a list of all potential bugs.
– IInspectable
Nov 23 '18 at 11:07
1
Looks like
bstrVal
is a unicode andcsField
a narrow string. This will work only if the system codepage is Cyrillic, andbstrVal
contains only characters that do exist in the Cyrrilic ANSI codepage. Unfortunately the system codepage can be set only globally, not per application. See a related answer in the link below: stackoverflow.com/questions/49872812/…– Constantine Georgiou
Nov 23 '18 at 12:50