快捷方式如果是中文名,读取其参数就错误!请高手指点一下
zolen 2005-01-18 04:42:08 微软的vb里带的例子,shelllink读取快捷方式是中文名的时候老是读取不了。不是所有中文名的快捷方式都这样。很晕。哪位高手帮忙看看,到底怎么回事情。比如你随便弄个程序创建一个快捷方式,名字叫“梦幻西游.lnk”,那就读取不了快捷方式里的信息了。
微软例子里读取信息的类模块:
Public Enum STGM
STGM_DIRECT = &H0&
STGM_TRANSACTED = &H10000
STGM_SIMPLE = &H8000000
STGM_READ = &H0&
STGM_WRITE = &H1&
STGM_READWRITE = &H2&
STGM_SHARE_DENY_NONE = &H40&
STGM_SHARE_DENY_READ = &H30&
STGM_SHARE_DENY_WRITE = &H20&
STGM_SHARE_EXCLUSIVE = &H10&
STGM_PRIORITY = &H40000
STGM_DELETEONRELEASE = &H4000000
STGM_CREATE = &H1000&
STGM_CONVERT = &H20000
STGM_FAILIFTHERE = &H0&
STGM_NOSCRATCH = &H100000
End Enum
Public Function GetShellLinkInfo(LnkFile As String, ExeFile As String, WorkDir As String, _
ExeArgs As String, IconFile As String, IconIdx As Long, _
ShowCmd As Long) As Long
'---------------------------------------------------------------
Dim pidl As Long ' Item id list
Dim wHotKey As Long ' Hotkey to shortcut...
Dim fd As WIN32_FIND_DATA
Dim Description As String
Dim buffLen As Long
Dim cShellLink As ShellLinkA ' An explorer IShellLink instance
Dim cPersistFile As IPersistFile ' An explorer IPersistFile instance
'---------------------------------------------------------------
If (LnkFile = "") Then Exit Function ' Validate min. input requirements.
Set cShellLink = New ShellLinkA ' Create new IShellLink interface
Set cPersistFile = cShellLink ' Implement cShellLink's IPersistFile interface
' Load Shortcut file...(must do this UNICODE hack!)
'On Error GoTo ErrHandler
cPersistFile.Load StrConv(LnkFile, vbUnicode), STGM_DIRECT
With cShellLink
' Get command line exe name & path of shortcut
ExeFile = Space(MAX_PATH)
buffLen = Len(ExeFile)
.GetPath ExeFile, buffLen, fd, SLGP_UNCPRIORITY
Dim s As String
s = fd.cFileName ' Not returned to calling function
' Get working directory of shortcut
WorkDir = Space(MAX_PATH)
buffLen = Len(WorkDir)
.GetWorkingDirectory WorkDir, buffLen
' Get command line arguments of shortcut
ExeArgs = Space(MAX_PATH)
buffLen = Len(ExeArgs)
.GetArguments ExeArgs, buffLen
' Get description of shortcut
Description = Space(MAX_PATH)
buffLen = Len(Description)
.GetDescription Description, buffLen ' Not returned to calling function
' Get the HotKey for shortcut
.GetHotkey wHotKey ' Not returned to calling function
' Get shortcut icon location & index
IconFile = Space(MAX_PATH)
buffLen = Len(IconFile)
.GetIconLocation IconFile, buffLen, IconIdx
' Get Item ID List...
.GetIDList pidl ' Not returned to calling function
' Set shortcut's startup mode (min,max,normal)
.GetShowCmd ShowCmd
End With
GetShellLinkInfo = True ' Return Success
'---------------------------------------------------------------
ErrHandler:
'---------------------------------------------------------------
Set cPersistFile = Nothing ' Destroy Object
Set cShellLink = Nothing ' Destroy Object
'---------------------------------------------------------------
End Function
'----------------
//////////////////////////////
cPersistFile.Load StrConv(LnkFile, vbUnicode), STGM_DIRECT
这一句遇到某些中文名就出错!!!