VB CreateFile函数中的参数始终报告说编译错误,ByRef参数类型不对?

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long

Private Type SECURITY_ATTRIBUTES
nLength As Long
bInheritHandle As Long
lpSecurityDescriptor As Long
End Type

Private Sub MYSub_Click()
Dim SA As SECURITY_ATTRIBUTES
FileHandle =CreateFile("C:\abc.jpeg", GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, SA, OPEN_EXISTING, 0, 0)
End Sub

当执行编译到CreateFile这行时,编译器报告说SA这个参数类型不对的错误,怎么解决这个问题呢?将SA替换为0或者1等,虽然编译能够通过,但得到的FileHandle 句柄值始终为-1,这与事实不符,导致后续的处理无法,要怎么设置这个SA值呢?
两位的方法都调试过了,都仍然报错,终于找到方法了,将SA 替换为vbNullString之后就成功了,但我不知道是为什么这么替换后就成功了。
分数不能浪费,先来先得吧。

四季花海
浏览 629回答 2
2回答

MMTTMM

SA你没赋值,只声明了变量的类型SA.lpSecurityDescriptor = &O0SA.bInheritHandle = FalseSA.nLength = Len(SecAttrib)
打开App,查看更多内容
随时随地看视频慕课网APP