Thread: How to convert string into LPCWSTR

  1. #1
    Registered User
    Join Date
    Jun 2009
    Location
    Bangalore,India
    Posts
    29

    How to convert string into LPCWSTR

    Hii

    How can I convert string into LPCWSTR



    Code:
     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 convert string to LPCWSTR  ....
    
    //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..

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    1) Call CreateFileA().

    2) Convert your string from whatever encoding it is in (presumably ASCII or UTF-8) to UTF-16. You can use MultiByteToWideChar() to accomplish this. Call it first with the last two arguments set to NULL and 0, respectively, and it will give you a buffer size. Allocate that buffer, call it again but passing the buffer, and you've got an LPWSTR. Then call CreateFileW(). Don't forget to free your memory.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Use a vector<WCHAR> if you convert yourself. But using CreateFileA is a better idea.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  2. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 12:47 PM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  4. ........ed off at functions
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2002, 09:37 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM