Do you need to expose IUknown Inteface WITHOUT INVOLING VB6?
Here to do it and it is straight compatible with Tb since no VB6 code involved.
Code:
Public Function GetIUnknown() As oleexp.IUnknown
Dim pISF As IShellFolder
Dim ppISF As Long
Dim pIUnk As oleexp.IUnknown
SHGetDesktopFolder ppISF
MoveMemory pISF, ppISF, 4
Set pIUnk = pISF
Set GetIUnknown = pIUnk
End Function
Public Function GetIUnknownFromPidl(ByVal pidl As Long) As oleexp.IUnknown
Dim pISF As IShellFolder
Dim pIUnk As oleexp.IUnknown
Dim pISI As IShellItem
Dim pIPAI As IParentAndItem
SHCreateItemFromIDList pidl, IID_IShellItem, pISI
Set pIPAI = pISI
pIPAI.GetParentAndItem 0, pISF, 0
Set pIUnk = pISF
Set GetIUnknownFromPidl = pIUnk
End Function
*HINT* All Sets can be changed to use MoveMemory (RTLCopyMemory as its real API name actually is).
Re: Do you need to expose IUknown Inteface WITHOUT INVOLING VB6?
All COM objects implement IUnknown at their root. You can always do a two-line set:
Code:
Dim pUnk As oleexp.IUnknown
Set pUnk = obj
Obj can be a Form, shell folder obtained from SHGetDesktopFolder, a VB class, and a million other COM objects, like IShellItem from SHCreateItemFromIDList.
Your second method, btw, gets an IUnknown not representing the pidl given, but representing its parent.
Set is VB code. Dim is VB code. No idea what you mean by 'NOT INVOLVING VB6'. The only VB6 stuff not compatible with tB is undocumented internals; all the language is supported.
(ps- while oleexp is compatible with 32bit tB, it's not 64bit compatible, and I strongly advise anyone using tB to use WinDevLib instead, where you'd use IUnknownUnrestricted in place of oleexp.IUnknown).
(pps- you don't need, and shouldn't use, MoveMemory here...
Public Declare PtrSafe Function SHGetDesktopFolder Lib "shell32" (ppshf As IShellFolder) As Long
Function GetIUnknownForDesktop() As oleexp.IUnknown
Dim pISF As IShellFolder
SHGetDesktopFolder pISF
Set GetIUnknownForDesktop = pISF
Or even simpler, let VB do it automatically
Dim pUnk As oleexp.IUnknown
SHGetDesktopFolder pUnk
Re: Do you need to expose IUknown Inteface WITHOUT INVOLING VB6?
The second alternative in my world I configurated it so the iShellfolder should ALWAYS be the parent to the pidl and not to itself. There is a big chance itself is not a folder. Are you buying my thought of binding to a iShellfolder?
Re: Do you need to expose IUknown Inteface WITHOUT INVOLING VB6?
An IShellItem representing a file instead of a folder also supports IUnknown. pidls aren't COM objects do don't support it regardless of which they refer to (and they can refer to either a file or folder).