I want to create a text file using windows API. I studied about
HANDLE CreateFile( LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDispostion , DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
I can't understand how to pass the first parameter to create a file. I tried to use data-type FILE and pass it's pointer as first parameter but it's showing incompatible with LPCTSTR. Can anybody tell me how to do it? I am new in using windows API. Thanks in advance.
preguntado el 09 de enero de 11 a las 07:01
LPCTSTR es el mismo que
const TCHAR* ("Long Pointer to a Constant
TCHAR-String"), which is either
const wchar_t* or
const char* depending on the character set. So just pass in a string surrounded by
_T(), me gusta:
CreateFile(_T("C:\\File.txt"), FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
FILE is not part of the Windows SDK; it's part of the standard C runtime library, and it's internally basado on
CreateFile, which creates a file based on its name.)
To create file with
CreateFile("OUTPUT_FILE", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
The first parameter is the name of the file which you can pass from any string variable..for example if the filename is in CString variable you can pass (LPCTSTR) variblename to convert it to LPCTSTR. all the other parameters are depending on your implementation whether you want to create the file always or append to existing file etc...