This function is ONE OF THE TOP MOST repeated and used function in my "Browse For Folder" UserControl so I felt a "guilt" to share it you all ;)
Because it's so handy och usable ;)
BUT be aware!! IF YOU is not confortable with Shell/COM programming or a beginner/novice I DO recommend YOU NOT use this function.
You do it best in to put this function into a class module so you don't have to write the function over and over again and just call it when needed...Like this:
HINT - You can switch out the SFGAO_FOLDER with whatever SFGAO_Flag(s) you whish.
Because it's so handy och usable ;)
BUT be aware!! IF YOU is not confortable with Shell/COM programming or a beginner/novice I DO recommend YOU NOT use this function.
Code:
Public Function IsShellItemFolder(pISI As IShellItem) As Boolean
'Long value for the bit wise attribute(s) you request(s)
Dim dwAttribs As Long
'The COM return result
Dim hr As Long
'Better to be safe than sorry - quit the function if IShellItem object not was set.
If pISI Is Nothing Then Exit Function
'Initialize Function to False - Ensure no old usage is left in the memory.
IsShellItemFolder = False
'Ask for attribute(s) and return the attributes wanted.
hr = pISI.GetAttributes(SFGAO_FOLDER, dwAttribs)
'If the method returned OK - Why shouldn't it?
If hr = S_OK Then
'Ask your "out pointer" if there is/are the request(ed) attributes in the "out pointer"
If (dwAttribs And SFGAO_FOLDER) Then
'If your query match the out pointer - return True
IsShellItemFolder = True
End If
Else
'OPTIONAL - Here you can make an output/notification to the user that the method in one way or another didn't returned OK.
'Error codes are ONLY in Hexadecimal valus for COM related errors so use Hex(hr) to find out the error code.
End If
End Function
Code:
Dim m_cShell32 As New cShell32 '<---- Put this Public/Global
Dim bIsFolder As Boolean
bIsFolder = m_cShell32.IsShellItemFolder(pISI_Enum)