CString results in ? when trying to assign _variant_t.bstrVal which contains russian chars












0















I am working on a desktop application.
I am facing this problem.



enter image description here



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.










share|improve this question


















  • 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 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


















0















I am working on a desktop application.
I am facing this problem.



enter image description here



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.










share|improve this question


















  • 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 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
















0












0








0








I am working on a desktop application.
I am facing this problem.



enter image description here



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.










share|improve this question














I am working on a desktop application.
I am facing this problem.



enter image description here



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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 4:42









Kishan VaishnavKishan Vaishnav

919




919








  • 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 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
















  • 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 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










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














1 Answer
1






active

oldest

votes


















0














*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("");





share|improve this answer























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    0














    *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("");





    share|improve this answer




























      0














      *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("");





      share|improve this answer


























        0












        0








        0







        *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("");





        share|improve this answer













        *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("");






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 3 '18 at 4:15









        Kishan VaishnavKishan Vaishnav

        919




        919






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'