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. How to convert string into LPCWSTR

How to convert string into LPCWSTR

Scheduled Pinned Locked Moved C / C++ / MFC
graphicstutorialquestion
2 Posts 2 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.
  • K Offline
    K Offline
    krish_kumar
    wrote on last edited by
    #1

    Hii How can I convert string into LPCWSTR

    struct FILELIST
    {
    string path;
    vector<string> theList;
    };

    string path
    list<FILELIST>& theList

    struct _finddatai64_t data;
    string fname = path + "\\*.*";
    long h = _findfirsti64(fname.c_str(),&data); //_findfirsti64(string,)




    //here I wanna conver[B]t string to LPCWSTR[/B] ....

    //using the LPCWSTR I've to open the file using Createfile()

    I've changed string to wstrig ,that time _findfirsti64() must have string argument...!! any idea.... Thanking you..

    C 1 Reply Last reply
    0
    • K krish_kumar

      Hii How can I convert string into LPCWSTR

      struct FILELIST
      {
      string path;
      vector<string> theList;
      };

      string path
      list<FILELIST>& theList

      struct _finddatai64_t data;
      string fname = path + "\\*.*";
      long h = _findfirsti64(fname.c_str(),&data); //_findfirsti64(string,)




      //here I wanna conver[B]t string to LPCWSTR[/B] ....

      //using the LPCWSTR I've to open the file using Createfile()

      I've changed string to wstrig ,that time _findfirsti64() must have string argument...!! any idea.... Thanking you..

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      You should really read this article[^], it will help you a lot understanding what you are doing wrong with your code. Basically, you should avoid these kind of conversions unless there is absolutely no other way. In your case, you can perfectly go without conversion. Your application is probably built for unicode support, so you should support that throughout your app: - use wstring if UNICODE is enabled by using your own string type everywhere in your app:

      #if defined _UNICODE || defined UNICODE
      typedef std::wstring TMyString;
      #else
      typedef std::string TMyString;
      #endif

      - instead of using _findfirsti64, you should use the unicode independant version (_tfindfirsti64). You should have a look at the documentation for all those functions, there is always a table with the different versions. But anyway, first thing to do is to read the article :)

      Cédric Moonen Software developer
      Charting control [v2.0] OpenGL game tutorial in C++

      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