Thread: Using LPCWSTR

  1. #1
    Registered User
    Join Date
    Jun 2006

    Using LPCWSTR


    I'm trying to open a file using the following code. However, I can't figure out how to get input from the user and either convert that string to a LPCWSTR or simply read the input as a LPCWSTR. Any suggestions?

    HANDLE OpenFile(LPCWSTR FileName, DWORD AccessMode)
       HANDLE FileHandle;
       DWORD  CreateAttribute;
       CreateAttribute = (AccessMode == GENERIC_READ)?OPEN_EXISTING:CREATE_ALWAYS;
       FileHandle = CreateFile(FileName, AccessMode, FILE_SHARE_READ, NULL, CreateAttribute, FILE_ATTRIBUTE_NORMAL, NULL);
    int main(int argc, char* argv[])
       DWORD   LengthIn, InFileSize, LengthOut, OutFileSize;
       HGLOBAL FileDataPtr;
       char infile[80];
       char outfile[80];
       printf("What's the input file? ");
       scanf("%s", infile);
       printf("\nWhat's the output file? ");
       scanf("%s", outfile);
       printf("What's the LevelMask:\n\nHCI=0x0001\nL2CAP=0x0002\nSDP=0x0004\nRFCOMM=0x0008\nOBEX=0x0010\nBNEP/PAN=0x0020\n");
       printf("\nTo Do Multiple Parsing:\nLogical AND Packet Types (ex. for HCI and L2CAP -> 0x0003)\n ?");
       scanf("%04X", &LevelMask);
       printf("What's the DumpMask:\n\nHCI=0x0001\nL2CAP=0x0002\nSDP=0x0004\nRFCOMM=0x0008\nOBEX=0x0010\nBNEP/PAN=0x0020\n");
       printf("\nTo Do Multiple Parsing:\nLogical AND Packet Types (ex. for HCI and L2CAP -> 0x0003)\n ?");
       scanf("%04X", &DumpMask);
       printf("%s %s 0x%04x 0x%04x\n", infile, outfile, LevelMask, DumpMask);
       InFile      = OpenFile(TEXT(infile), GENERIC_READ);
       OutFile     = OpenFile(TEXT(outfile), GENERIC_WRITE);
    If I hard code in my input and output files, this code works. I'm not too familiar with using LPCWSTR's, so any help would be appreciated.

  2. #2
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    To convert from ANSI to UNICODE use

    or you can do everything in your APP in UNICODE. You must #define UNICODE in your project though
    Use _T("STRING") macro found in <TCHAR.h>
    Use TCHAR or w_char instead of char
    Use std::wstring instead of std::string
    and use the UNICODE functions
    wprintf() instead of printf()
    wscanf() instead of scanf()
    for others use MSDN to look up their UNICODE equivalents
    My Website
    Add Color To Your Code!

  3. #3
    Registered User
    Join Date
    Jun 2006
    Thanks that worked!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to convert string into LPCWSTR
    By krishnampkkm in forum C++ Programming
    Replies: 2
    Last Post: 06-15-2009, 06:02 AM
  2. message box LPCWSTR manipulation and keyword question
    By stanlvw in forum Windows Programming
    Replies: 11
    Last Post: 05-27-2008, 12:36 PM
  3. a type problem (TCHAR, LPCWSTR)
    By Crazed in forum Windows Programming
    Replies: 6
    Last Post: 03-13-2008, 01:19 PM
  4. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  5. Lpcwstr
    By unregistered in forum Windows Programming
    Replies: 1
    Last Post: 07-08-2002, 03:02 PM