Maximus5 / ConEmu

Customizable Windows terminal with tabs, splits, quake-style, hotkeys and more
https://conemu.github.io/
BSD 3-Clause "New" or "Revised" License
8.64k stars 580 forks source link

ConEmu cause Windows API WriteFile to return set InvalidHandle error #415

Open chossette opened 9 years ago

chossette commented 9 years ago

Hi,

The Windows API function WriteFile set LastError to 6 (InvalidHandle) when program is runned under ConEmu, but the data are well written. The same program run from the same location does not get this error when run from cmd.exe or console2.

The compilation is done using Visual Studio 2008 SP1. Issue is present if built in 32 and 64bits, debug or release. OS is Windows 7 64bits professional, ConEmu is version 150707 [64]

Here is a minimal sample to reproduce the issue:

#include <windows.h>
#include <iostream>

const wchar_t *wfilename = L"F:\\temp\\writing_file.log";
const unsigned char buffer[2048] = { 0 };

int main(int argc, char* argv[])
{
  HANDLE handle = CreateFileW(wfilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  DWORD lastError = GetLastError();
  std::cout << "File created (le: " << lastError << "), handle: 0x" << std::hex << handle << std::endl;

  system("pause");
  DWORD written = 0;
  BOOL res = WriteFile(handle, buffer, 2048, &written, NULL);
  lastError = GetLastError();
  std::cout << "File write (le: " << std::dec << lastError << "), handle: 0x" << std::hex << handle << ", written: " << std::dec << written << std::endl;

  CloseHandle(handle);

  return 0;
}

Test have been done by adding an empty overlap structure, but issue is still present, and overlap structure content says that data have been written.

Tx ! Nicolas,

Maximus5 commented 9 years ago

https://conemu.github.io/en/OldBuild.html

chossette commented 9 years ago

Hi,

I just updated conemu to the last version : alpha 151109 (I thought that update was auto).

The issue is still present,

Nicolas,