开发者

VB6: CreateFile() creates file with garbled name in current working directory

开发者 https://www.devze.com 2023-03-08 05:48 出处:网络
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:

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 lpSe开发者_如何学GocurityAttributes 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?


It's been a long time, but I think this is an ansi/unicode thing. Try the CreateFileA function and see what happens. (Also, IIRC, you don't escape the \ ....although again it's been about 7 years since I seriously coded with VB6.)

0

精彩评论

暂无评论...
验证码 换一张
取 消