Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. char to BSTR

char to BSTR

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++
5 Posts 3 Posters 9 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    roadragedave
    wrote on last edited by
    #1

    Im a novice at C++ and Im working on VisualC++.NET on w2k, what am I doing wrong here: Code: BSTR McName = SysAllocString(TEXT("DaveMachine")); Error: error C2664: 'SysAllocString' : cannot convert parameter 1 from 'const char [11]' to 'const OLECHAR *' Any help is really appreciated. We have a mathematician, a different kind of mathematician, and a statistician!

    D 1 Reply Last reply
    0
    • R roadragedave

      Im a novice at C++ and Im working on VisualC++.NET on w2k, what am I doing wrong here: Code: BSTR McName = SysAllocString(TEXT("DaveMachine")); Error: error C2664: 'SysAllocString' : cannot convert parameter 1 from 'const char [11]' to 'const OLECHAR *' Any help is really appreciated. We have a mathematician, a different kind of mathematician, and a statistician!

      D Offline
      D Offline
      Diddy
      wrote on last edited by
      #2

      SysAllocString takes a Unicode string as it's parameter. If you don't have _UNICODE defined - TEXT() evalulates to nothing. Always pass a Unicode string to SysAllocString like this BSTR McName = SysAllocString(L"DaveMachine");

      R 1 Reply Last reply
      0
      • D Diddy

        SysAllocString takes a Unicode string as it's parameter. If you don't have _UNICODE defined - TEXT() evalulates to nothing. Always pass a Unicode string to SysAllocString like this BSTR McName = SysAllocString(L"DaveMachine");

        R Offline
        R Offline
        roadragedave
        wrote on last edited by
        #3

        Excellent, that got rid of a few errors, just one to go. This is the code: wsprintf(sz, TEXT("Load Percentage: %s\n"), V_BSTR(&vVal)); wprintf(sz); and the error is pretty similar to the last one: error C2664: 'wprintf' : cannot convert parameter 1 from 'TCHAR [260]' to 'const wchar_t *' Cheers We have a mathematician, a different kind of mathematician, and a statistician!

        D PJ ArendsP 2 Replies Last reply
        0
        • R roadragedave

          Excellent, that got rid of a few errors, just one to go. This is the code: wsprintf(sz, TEXT("Load Percentage: %s\n"), V_BSTR(&vVal)); wprintf(sz); and the error is pretty similar to the last one: error C2664: 'wprintf' : cannot convert parameter 1 from 'TCHAR [260]' to 'const wchar_t *' Cheers We have a mathematician, a different kind of mathematician, and a statistician!

          D Offline
          D Offline
          Diddy
          wrote on last edited by
          #4

          Same thing - if Unicode is not defined TEXT = nothing, if it is TEXT = L. Thats fine, but your using the wide (UNICODE) version of wsprintf so its expecting a Unicode string. Either change TEXT to L or use char neutral APIs. Basically, never use TEXT with the explicilty wide (say wsprintf) or explictly narrow (say sprintf) versions of functions as you know what type of char to pass ("" in narrow, or L"" in wide). Use TEXT when you want to be char neutrual - using the API's - _stprintf. With UNICODE defined _stprintf = wsprintf and TEXT = L"". Without UNICODE define _stprintf = sprintf and TEXT = "".

          1 Reply Last reply
          0
          • R roadragedave

            Excellent, that got rid of a few errors, just one to go. This is the code: wsprintf(sz, TEXT("Load Percentage: %s\n"), V_BSTR(&vVal)); wprintf(sz); and the error is pretty similar to the last one: error C2664: 'wprintf' : cannot convert parameter 1 from 'TCHAR [260]' to 'const wchar_t *' Cheers We have a mathematician, a different kind of mathematician, and a statistician!

            PJ ArendsP Offline
            PJ ArendsP Offline
            PJ Arends
            wrote on last edited by
            #5

            See also http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfcnotes_tn059.asp[^]


            [

            ](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!

            Within you lies the power for good; Use it!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups