Have you ever wondered over how to get a PIDL from a NET object (WWW or FTP or //Netpath)?
Here it comes as the most simple way.
First you create a IShellItem from the URL path since the IShellItem in comparison to IShellFolder is more versitile and not bound to the local machine with this API:
Code:
Private Declare Function SHCreateItemFromParsingName Lib "shell32.dll" (ByVal pszPath As Long, ByVal pIBindCtx As Long, riid As Any, ByRef ppv As Any) As Long
After you have successfully created a IShellItem you take this IShellItem and call the following API:
Code:
Private Declare Function SHGetIDListFromObject Lib "shell32.dll" (ByVal pUnk As Long, ByRef ppidl As Long) As Long
Just ONLY theese two API's are the fundamental back end in this example.
I did add some more API's and GUI stuff in the front end just to make it more nice.
Code:
Private Sub Form_Load()
Text1.Text = "ftp://ftp.sunet.se"
ExtractIconEx "shell32.dll", 43, 0, hSmall, 1
SendMessage Form1.hWnd, WM_SETICON, ByVal 0, ByVal hSmall
End Sub
Private Sub Command1_Click()
Dim pISI As IShellItem
Dim hr As Long
Dim pidl As Long
Dim hIcon As Long
hr = SHCreateItemFromParsingName(StrPtr(Text1.Text), 0&, IID_IShellItem, pISI)
If hr = 0 Then
SHGetIDListFromObject ObjPtr(pISI), pidl
If pidl > 0 Then
Text2.Text = CLng(pidl)
hIcon = GetItemIconHandle(pidl, True)
Set Picture1 = Nothing
DrawIcon Picture1.hdc, 0, 0, hIcon
CoTaskMemFree pidl
DestroyIcon hIcon
End If
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
DestroyIcon hSmall
End Sub
Private Sub Form_Terminate()
DestroyIcon hSmall
End Sub
Private Sub Form_Unload(Cancel As Integer)
DestroyIcon hSmall
End Sub
This function is only for the front end GUI purposes!!
Code:
Private Function GetItemIconHandle(ByVal pidl As Long, Optional ByVal bLargeIcon As Boolean) As Long
Dim lpSHFI As SHFILEINFO
Dim lr As Long
Dim hIcon As Long
If bLargeIcon = True Then
lr = SHGetFileInfo(pidl, 0, lpSHFI, LenB(lpSHFI), SHGFI_PIDL Or SHGFI_ICON Or SHGFI_LARGEICON Or SHGFI_ICONLOCATION)
Else
lr = SHGetFileInfo(pidl, 0, lpSHFI, Len(lpSHFI), SHGFI_PIDL Or SHGFI_ICON Or SHGFI_SMALLICON)
End If
GetItemIconHandle = lpSHFI.hIcon
End Function
Full Source Code below - You need to use oleexp or similar typelib that exposes the IShellItem Interface.
THIS IS A COM/SHELL32 EXAMPLE AND IT'S RECOMMENED YOU HAVE SOME SKILLS IN COM AND SHELL32 API PROGRAMMING.
HAVE FUN