createfile

CreateFile not able to share serial (COM) port

南楼画角 提交于 2021-02-17 06:46:21
问题 The CreateFile function is useful for opening files or devices for read/write access, providing a handle. The third parameter, dwShareMode , specifies if the file/device can later be accessed by others. An example, with files: void* pFileHandle1 = ::CreateFileA("C:\\test.txt", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); DWORD lastError = GetLastError(); // 0, ERROR_SUCCESS void* pFileHandle2 = ::CreateFileA("C:\\test.txt", GENERIC_READ|GENERIC_WRITE,

vba check if directory exists, if exists exit sub else if does not exist, create

徘徊边缘 提交于 2021-02-17 05:21:13
问题 Ok so I have the following vba code which I am using to check if a directory exists and if not create the folder structure like so: If Dir("S:\Tasks\" & Range("C" & ActiveCell.Row).Value & "\" & Range("M" & ActiveCell.Row).Value & "\" & Range("Z" & ActiveCell.Row).Value, vbDirectory) = "" Then MkDir Path:="S:\Tasks\" & Range("C" & ActiveCell.Row).Value & "\" & Range("M" & ActiveCell.Row).Value & "\" & Range("Z" & ActiveCell.Row).Value MsgBox "Done" Else MsgBox "found it" End If So my

Why is CreateFileA failing only when the executable is run under Visual Studio?

北战南征 提交于 2021-02-05 10:39:58
问题 I wrote a simple check_file_ref function using WinAPI to check whether two paths reference the same file. The code is fine. It's compiled with Visual Studio 2017 in C (flag /TC ). The weird thing is CreateFileA (winapi) always fails when the executable is run under Visual Studio (ie execute without debugging), returning an invalid file handle. Otherwise, it works as expected when the executable is run outside of Visual Studio. The working dir is the same in any case. main.c: #include <stdio.h

Why is CreateFileA failing only when the executable is run under Visual Studio?

丶灬走出姿态 提交于 2021-02-05 10:39:07
问题 I wrote a simple check_file_ref function using WinAPI to check whether two paths reference the same file. The code is fine. It's compiled with Visual Studio 2017 in C (flag /TC ). The weird thing is CreateFileA (winapi) always fails when the executable is run under Visual Studio (ie execute without debugging), returning an invalid file handle. Otherwise, it works as expected when the executable is run outside of Visual Studio. The working dir is the same in any case. main.c: #include <stdio.h

Read text file (Unicode) in 'C' using native Win32

亡梦爱人 提交于 2021-01-27 05:42:20
问题 I have a line-oriented text file (Unicode) that was created using CreateFile() and WriteFile(). Reading that file as a binary stream using ReadFile() is straightforward, but extra low-level processing is needed to break it into lines. Is there a Win32 function that does this for me? Again, please note that it's in 'C' (not C++) and I don't want to use POSIX/ANSI C functions such as readline(). If the answer to the aforementioned question is negative, what would be the "shortest code" to

CreateFile() Serial Communication Issue [duplicate]

爱⌒轻易说出口 提交于 2020-12-03 07:41:49
问题 This question already has an answer here : How to open COMXX files(serial port) (1 answer) Closed 5 years ago . I am trying to do some serial communication through my usb port (named COM15), and I am getting an error. This is the code where the error is occurring: HANDLE myPortHandle = CreateFile("COM15", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (myPortHandle == INVALID_HANDLE_VALUE) { DWORD lastError = GetLastError(); cout<<"ERROR HERE! = "<<lastError<<endl; } Every

File.createTempFile in Java getting Incompatible type error

◇◆丶佛笑我妖孽 提交于 2020-06-29 03:52:16
问题 Till now my code works fine where I am creating file in temporary directory and processing it. But now I am trying to provide specific directory where I actually want to create xml file. So in method createTmpXmlFile private static Path createTmpXmlFile(final String prefix) { try { log.info("Creating temporary file {}{}", prefix, XML_SUFFIX); return Files.createTempFile(Paths.get(gleifZipFile), prefix, XML_SUFFIX); } catch (IOException e) { throw new IllegalStateException("Could not create