-
February 6th, 2009, 02:57 PM
#1
Text File Writing
Want to write a text file to save log data during app runtime. Grabbed this code from MSDN itself, and it doesnt compile.
HANDLE hFile = CreateFile(_T("C:\\TEMP\\MyFile.txt"),
GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
AfxMessageBox(_T("Couldn't create the file!"));
else
{
CFile myFile(hFile);
static const char sz[] = "Hockey is best!";
myFile.Write(sz, lstrlen(sz));
myFile.Close();
}
This is the error
'lstrlenW' : cannot convert parameter 1 from 'const char [16]' to 'LPCWSTR'
What am I doing wrong?
-
February 6th, 2009, 03:39 PM
#2
Re: Text File Writing
Your project is set for Unicode, and the code you show is not. There's a setting in the project properties that lets you change that.
Here's the offending line:
Code:
static const char sz[] = "Hockey is best!";
You could change it to
Code:
static const wchar_t sz[] = _T("Hockey is best!");
Hope that helps.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
February 6th, 2009, 04:06 PM
#3
Re: Text File Writing
Thanks - no more error during compilation, but only getting garbage characters in the text file...How do I fix that?
-
February 6th, 2009, 04:52 PM
#4
Re: Text File Writing
How did you test your file to conclude it contains "garbage"?
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|