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 LongPrivate Type SECURITY_ATTRIBUTESnLength As LongbInheritHandle As LonglpSecurityDescriptor As LongEnd TypePrivate Sub MYSub_Click()Dim SA As SECURITY_ATTRIBUTESFileHandle =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之后就成功了,但我不知道是为什么这么替换后就成功了。分数不能浪费,先来先得吧。
2 回答
MMTTMM
TA贡献1869条经验 获得超4个赞
SA你没赋值,只声明了变量的类型
SA.lpSecurityDescriptor = &O0
SA.bInheritHandle = False
SA.nLength = Len(SecAttrib)
- 2 回答
- 0 关注
- 628 浏览
添加回答
举报
0/150
提交
取消