VB6:CreateFile() 在当前工作目录中创建名称乱码的文件

发布于 2024-11-10 02:15:54 字数 690 浏览 0 评论 0原文

当我发现 CreateFile() 不能很好地使用文件名参数时,我正在对 CreateFile 无法打开现有命名管道的问题进行故障排除。我的代码是:

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&)

它不会在C:\中创建文件,而是在当前VB工作目录中创建一个文件,文件名是乱码。 CreateFile 似乎无法识别和解析给定的文件名字符串。

为什么会发生这种情况?我在 Windows 7 上使用 VB6(使用一些技巧来安装它)。这可能是导致问题的原因吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁吢 2024-11-17 02:15:54

已经很久了,但我认为这是 ansi/unicode 的事情。尝试 CreateFileA 函数,看看会发生什么。 (另外,IIRC,你无法逃避 \ ....尽管距离我认真使用 VB6 编码已经过去了大约 7 年。)

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文