#define UNICODE // comment this line if you want to compile as ansi
#include <windows.h>
int main()
{
TCHAR szText[] = TEXT("C:\\Documents and Settings\\Administrator\\桌面\\中文.txt\n");
DWORD dwBytesWrite;
WORD magic = 0xFEFF;
HANDLE hFile = CreateFile(TEXT("C:\\test.txt"), GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if ( INVALID_HANDLE_VALUE == hFile )
return -1;
#ifdef UNICODE
WriteFile(hFile, &magic, sizeof(WORD), &dwBytesWrite, NULL);
#endif
WriteFile(hFile, szText, lstrlen(szText) * sizeof(TCHAR), &dwBytesWrite, NULL);
CloseHandle(hFile);
return 0;
}
|