调试的时候老是说:编译错误:
用户定义类型未定义这是什么原因呢?????????
代码如下:
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 Sub Command2_Click()
Call CreateFile("c:\test.txt", GENERIC_READ, FILE_SHARE_READ, FILE_SHARE_WRITE, Null, OPEN_EXISTING, FILE_ELAG_OVERLAPPED, Null)
End Sub
用户定义类型未定义这是什么原因呢?????????
代码如下:
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 Sub Command2_Click()
Call CreateFile("c:\test.txt", GENERIC_READ, FILE_SHARE_READ, FILE_SHARE_WRITE, Null, OPEN_EXISTING, FILE_ELAG_OVERLAPPED, Null)
End Sub
' Form Code
'Add four command buttons in a control array to a form (Command1(0)-
'Command1(3)), and add the following code:
'------------------------------------------------------------------------------
Option ExplicitPrivate Declare Function SetErrorMode Lib "kernel32" _
(ByVal wMode As Long) As LongPrivate Declare Function CreateFile Lib "kernel32" _
Alias "CreateFileA" _
(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
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As LongPrivate Const SEM_FAILCRITICALERRORS = &H1
Private Const SEM_NOOPENFILEERRORBOX = &H8000&
Private Const OPEN_EXISTING As Long = 3
Private Const OPEN_ALWAYS As Long = 4
Private Const FILE_SHARE_READ As Long = &H1
Private Const FILE_SHARE_WRITE As Long = &H2
Private Const GENERIC_READ As Long = &H80000000
Private Const GENERIC_WRITE As Long = &H40000000
Private Const INVALID_HANDLE_VALUE = -1
Private Sub Command1_Click(Index As Integer) Dim success As Boolean
Select Case Index
Case 0: success = IsUsualDirFloppyDriveReady("A:")
Case 1: success = IsFileSysFloppyDriveReady("A:")
Case 2: success = IsDirFloppyDriveReady("A:")
Case 3: success = IsVolumeReady("\\.\A:")
End Select
If success Then
MsgBox "Drive Test: The drive is ready."
Else: MsgBox "Drive Test: The drive is not ready."
End If
End Sub
Public Function IsUsualDirFloppyDriveReady(sDrive As String) As Boolean 'do a Dir on the drive.
On Error Resume Next
IsUsualDirFloppyDriveReady = Dir(sDrive) <> ""
On Local Error GoTo 0
End Function
Private Function IsDirFloppyDriveReady(sDrive As String) As Boolean On Local Error Resume Next
Dim oldErrMode As Long 'suspend floppy disk errors
oldErrMode = SetErrorMode(SEM_FAILCRITICALERRORS)
'do a Dir on the drive.
IsDirFloppyDriveReady = Dir(sDrive) > ""
'Put things back the way you found them
Call SetErrorMode(oldErrMode)
On Local Error GoTo 0End Function
Private Function IsFileSysFloppyDriveReady(sDrive As String) As Boolean Dim fs As FileSystemObject
Set fs = New FileSystemObject
IsFileSysFloppyDriveReady = fs.GetDrive(sDrive).IsReady Set fs = Nothing
End Function
Private Function IsVolumeReady(sDrive As String) As Boolean Dim hFile As Long hFile = CreateFile(sDrive, _
GENERIC_READ Or GENERIC_WRITE, _
FILE_SHARE_READ Or FILE_SHARE_WRITE, _
0&, _
OPEN_EXISTING, _
0, _
0&)
IsVolumeReady = hFile <> INVALID_HANDLE_VALUE Call CloseHandle(hFile)
End Function
小弟是初学者
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
需要设置SECURITY_ATTRIBUTES:Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type