CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2000
    Location
    Tehran - Iran
    Posts
    949

    Convert char * to OLECHAR *

    Hi all.
    How can i convert char * variable to OLECHAR * variable ???


    My month article: Game programming by DirectX by Lan Mader.
    Please visit in: www.geocities.com/hadi_rezaie/index.html

    Hadi Rezaie

  2. #2
    Join Date
    May 1999
    Location
    Germany
    Posts
    106

    Re: Convert char * to OLECHAR *

    Hi Hadi Rezaie,

    you can use

    size_t mbstowcs( wchar_t *wcstr, const char *mbstr, size_t count );



    because OLECHAR is wchar_t.

    Bye
    Peter






  3. #3
    Join Date
    Oct 2000
    Location
    Tehran - Iran
    Posts
    949

    Re: Convert char * to OLECHAR *

    hmmm, i read MSDN, yeah OLECHAR = wchar_t ...
    But i didn't understand how can i convert !!!
    Can you write any code ?


    My month article: Game programming by DirectX by Lan Mader.
    Please visit in: www.geocities.com/hadi_rezaie/index.html

    Hadi Rezaie

  4. #4
    Join Date
    Aug 1999
    Posts
    586

    Re: Convert char * to OLECHAR *

    See http://www.codeguru.com/cgi-bin/bbs/...age=&view=&sb=

    In your case:

    #include <atlconv.h>
    ...

    USES_CONVERSION;
    LPCOLESTR poleString = OLESTR("Whatever");
    const char *pString = OLE2CA(poleString); // Macro converts "OLECHAR" string to constant "char" string





  5. #5
    Join Date
    May 1999
    Location
    Germany
    Posts
    106

    Re: Convert char * to OLECHAR *

    Hi,

    hope this short example helps.

    Bye
    Peter

    ...
    #include <windows.h>
    #include <objbase.h>
    ...
    void MyMessageBox(char *sText)
    {
    // reserve memory for the OLECHAR-string
    OLECHAR *sOleText=new OLECHAR[strlen(sText)+1];

    // convert the char-string to OLECHAR-string
    mbstowcs(sOleText,sText,strlen(sText)+1); // +1 means: don't forget the terminating null character

    // show content of OLECHAR-string by calling the wide-character-version of MessageBox
    MessageBoxW(GetDesktopWindow(),sOleText,OLESTR("Caption"),MB_OK);

    // free memory of the OLECHAR-string
    delete sOleText;
    }





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured