I was troubleshooting a problem where CreateFile couldn't open an existing named pipe when I found CreateFile() didn't work well with the filename parameter. My code is:
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileW" ( _
ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
ByVal lpSecurityAttributes As Long, _
ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long
pipeHandle = CreateFile("C:\\test.txt", GENERIC_READ Or GENERIC_WRITE, 0&, 0&, CREATE_ALWAYS, 0&, 0&)
It does not create the file in C:\, instead, it creates a file in the current VB working directory, with a garbled filename. It seems CreateFile cannot recognize and parse the given filename string.
Why is this happening? I'm using VB6 on Windows 7 (used some trick to install it). Could that be causing the problem?