Открываю файл с доступом на чтение/запись - успешно Запись же не успешна, GetLastError возвращает 5. вопрос почему?.. Код (Text): void ErrorExit(LPTSTR lpszFunction) { // Retrieve the system error message for the last-error code LPVOID lpMsgBuf; LPVOID lpDisplayBuf; DWORD dw = GetLastError(); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); // Display the error message and exit the process lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, (lstrlen((LPCTSTR)lpMsgBuf)+lstrlen((LPCTSTR)lpszFunction)+40)*sizeof(TCHAR)); StringCchPrintf((LPTSTR)lpDisplayBuf, LocalSize(lpDisplayBuf), TEXT("%s failed with error %d: %s"), lpszFunction, dw, lpMsgBuf); MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK); LocalFree(lpMsgBuf); LocalFree(lpDisplayBuf); // ExitProcess(dw); }; void GateFunc(IN PBYTE pbData, IN DWORD dwSize){ if (_GateFunc){ _GateFunc(pbData,dwSize); } else{ MessageBox(0,"GateFunc = NULL","",0); }; HANDLE hFile = CreateFile("C:\\log_txt.txt",GENERIC_WRITE||GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,0); if (hFile == INVALID_HANDLE_VALUE) ErrorExit("CreateFile"); if(SetFilePointer(hFile,0,0,FILE_END) == INVALID_SET_FILE_POINTER) ErrorExit("SetFilePointer"); if(!WriteFile(hFile,pbData,dwSize,&dwSize,NULL)) ErrorExit("WriteFile"); if(!WriteFile(hFile,"ABC0",4,&dwSize,NULL)) ErrorExit("WriteFile"); CloseHandle(hFile); };