
Signature
Dean Earley (dean.earley@icode.co.uk)
i-Catcher Development Team
iCode Systems
>> Hi all,
>>
[quoted text clipped - 21 lines]
> You'll have to show us some of your code.
> It sounds like a memory allocation problem.
Strange enough (?), my code works on WinXP like a charm, and it does
also work on Win2K for registered file types.
My first opinion was also a memory allocation problem or a bad calling
convention (ByVal instead of ByRef or vice versa) but that doesn't
explain why it works for registered file types. In that case I would
expect it to fail every time.
Nevertheless, here's snippet of my implementation:
<code>
'SHGetFileInfo Flags
Private Const SHGFI_USEFILEATTRIBUTES As Long = &H10
Private Const SHGFI_TYPENAME As Long = &H400
'FileAttribute flags
Private Const FILE_ATTRIBUTE_DIRECTORY As Long = &H10
Private Const FILE_ATTRIBUTE_NORMAL As Long = &H80
Private Type SHFILEINFO _SHFILEINFO {
hIcon As Long
iIcon As Long
dwAttributes As Long
szDisplayName(519) As Byte
szTypeName(159) As Byte
End Type
Private Declare Function SHGetFileInfo Lib "shell32.dll" _
Alias "SHGetFileInfoW" ( _
ByVal pszPath As Long, _
ByVal dwFileAttributes As Long, _
psfi As SHFILEINFO, _
ByVal cbSizeFileInfo As Long, _
ByVal uFlags As Long) As Long
Private Sub GetFileInfo()
'mvarExtension is initialized in the class
On Error GoTo ErrHandler
Static shInfo As SHFILEINFO, shInfoStructSize As Long
Dim lRetval As Long
If shInfoStructSize = 0 Then
shInfoStructSize = Len(shInfo)
'working variables...
Dim sExtension As String, lFileAttributes As Long
Dim lFlags As Long, sTypeName As String
If mvarExtension = vbNullChar Then
lFileAttributes = FILE_ATTRIBUTE_DIRECTORY
sExtension = ""
Else
lFileAttributes = FILE_ATTRIBUTE_NORMAL
sExtension = "." & mvarExtension
End If
'Get the system TypeName associated with that extension
lFlags = SHGFI_TYPENAME Or SHGFI_USEFILEATTRIBUTES
lRetval = SHGetFileInfo( _
ByVal StrPtr(sExtension), lFileAttributes, shInfo, _
shInfoStructSize, lFlags)
If lRetval <> 0 Then
sTypeName = shInfo.szTypeName 'Implicit conversion!
mvarFileType = Left(sTypeName, _
InStr(1, sTypeName, vbNullChar) - 1)
Else
GoSub LogAPIError_GetFileInfo
End If
'Else
' GetFileInfo() called before for the given extension
End If
Exit Sub
LogAPIError_GetFileInfo:
'Some Warning Error Routine here
Resume
ErrHandler:
'Some Error Handling Routine here
End Sub
</code>
Note this snippet is only part of my implementation, so if some
declarations are missing, it's due to the selective copy-paste.
Sinna