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. Passing PCWSTR to a function

Passing PCWSTR to a function

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structurestutorial
3 Posts 3 Posters 0 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.
  • V Offline
    V Offline
    Vickie
    wrote on last edited by
    #1

    Dear all, How can I pass the string in a char array or CString array in this Speak() function? e.g. char chararray[5][5]; chararray[0] = "Hello"; or CString cstringarray[5][5]; cstringarray[0] = "How are you"; HRESULT Speak (PCWSTR pszSpeak); Since the parameter should be a pointer of WCHAR, do anyone know how to convert the string to the suitable parameter? Looking forward to your sincere reply. Thanks a lot!

    M L 2 Replies Last reply
    0
    • V Vickie

      Dear all, How can I pass the string in a char array or CString array in this Speak() function? e.g. char chararray[5][5]; chararray[0] = "Hello"; or CString cstringarray[5][5]; cstringarray[0] = "How are you"; HRESULT Speak (PCWSTR pszSpeak); Since the parameter should be a pointer of WCHAR, do anyone know how to convert the string to the suitable parameter? Looking forward to your sincere reply. Thanks a lot!

      M Offline
      M Offline
      Matt W
      wrote on last edited by
      #2

      Vickie, usually when I write applications I decide to either use wide characters (Unicode) strings everywhere or to use normal characters thus avoiding problems like yours. But I have had the same problem you are having numerous times. There are two ways that I have used to convert plain old char arrays to wide characters: 1. Windows provides two API calls to help things along: WideCharToMultiByte and MultiByteToWideChar these functions take quite a few parameters and can be quite cumbersome to use. 2. Use wcstombs and mbstowcs (this is the method I prefere). Look them up in your doco but this will give you an idea: char mBuf[255]; wchar_t wBuf[255]; i = mbstowcs( bBuf, mBuf, 255 ); hope this helps ;) Accept that some days you are the pigeon and some days the statue.

      1 Reply Last reply
      0
      • V Vickie

        Dear all, How can I pass the string in a char array or CString array in this Speak() function? e.g. char chararray[5][5]; chararray[0] = "Hello"; or CString cstringarray[5][5]; cstringarray[0] = "How are you"; HRESULT Speak (PCWSTR pszSpeak); Since the parameter should be a pointer of WCHAR, do anyone know how to convert the string to the suitable parameter? Looking forward to your sincere reply. Thanks a lot!

        L Offline
        L Offline
        l a u r e n
        wrote on last edited by
        #3

        ummm is the app a unicode (or wide char) app? if so all your strings will be wide char so passing a string ptr is as easy as Speak(szString) or Speak ((LPCTSTR)csString) if the app isnt unicode then u have to use the conversion macros USES_CONVERSION; W2A(blah blah blah) A2W(blee blee blee) ;) mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them

        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