用 SHGetFileInfo 不能获得文件类型描述!!! (200分)

  • 主题发起人 主题发起人 triumph
  • 开始时间 开始时间
T

triumph

Unregistered / Unconfirmed
GUEST, unregistred user!
Private Const SHGFI_LARGEICON = &H0
Private Const SHGFI_SMALLICON = &H1
Private Const SHGFI_OPENICON = &H2
Private Const SHGFI_SHELLICONSIZE = &H4
Private Const SHGFI_PIDL = &H8
Private Const SHGFI_USEFILEATTRIBUTES = &H10
Private Const SHGFI_ICON = &H100
Private Const SHGFI_DISPLAYNAME = &H200
Private Const SHGFI_TYPENAME = &H400
Private Const SHGFI_ATTRIBUTES = &H800
Private Const SHGFI_ICONLOCATION = &H1000
Private Const SHGFI_EXETYPE = &H2000
Private Const SHGFI_SYSICONINDEX = &H4000
Private Const SHGFI_LINKOVERLAY = &H8000
Private Const SHGFI_SELECTED = &H10000
<StructLayout(LayoutKind.Sequential)> _
Private Structure SHFILEINFO
Public hIcon As IntPtr
Public iIcon As Integer
Public dwAttributes As Integer
<MarshalAs(UnmanagedType.LPStr, SizeConst:=260)> _
Public szDisplayName As String
<MarshalAs(UnmanagedType.LPStr, SizeConst:=80)> _
Public szTypeName As String
End Structure
Private Declare Auto Function SHGetFileInfo Lib "shell32" (ByVal pszReadFilePath As String, ByVal dwFileAttributes As Integer, ByRef psfi As SHFILEINFO, ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As Integer
Function GetFileType(ByVal fn As String) As String
Dim aSHFileInfo As New SHFILEINFO
Dim R As String
R = "未知类型"
Try
SHGetFileInfo(fn, 0, aSHFileInfo, Marshal.SizeOf(aSHFileInfo), SHGFI_TYPENAME Or SHGFI_EXETYPE Or SHGFI_USEFILEATTRIBUTES)
R = aSHFileInfo.szTypeName '<==这里获得的总是 Nothing
Finally
GetFileType = R
End Try
End Function
获得的结果为 Nothing
为什么?在 Delphi 中用同样的方法轻松就获得了!
在 CSDN 问了无数次,无人能答,希望真正的高手在这里!
 
后退
顶部