-
Using LPCWSTR
Hi,
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?
Code:
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);
return(FileHandle);
}
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.
-
To convert from ANSI to UNICODE use http://msdn.microsoft.com/library/de...icode_17si.asp
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
-