473,386 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

iShellFolder, BindToObjects and IiEnumIdList in VB.Net

Hi all,
I need to enumerate pidl in a directory which I got (I think) the rigt
pidl, but I don't know how to procede.

here is a piece of code (folder is a IShellFolder object and it seems to
work correctly)

Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr
folder.EnumObjects(IntPtr.Zero, _
COM.ShellAPI.API.SHCONTF.SHCONTF_FOLDERS Or _
COM.ShellAPI.API.SHCONTF.SHCONTF_NONFOLDERS, _
pidEnum)

Now pidEnum got a value and this make me thind folder.EnumObjects works
well
but OF COURSE idEnum (which I must use) is Nothing since is not initialized
so I can't use
Dim hRes As Integer
hRes = idEnum.Next(1, pidl, fetched)

I tried:
Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr =
Marshal.AllocHGlobal(Marshal.SizeOf(idEnum))
' this give me an error "Value can't be null"

I also tried:
Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr
folder.EnumObjects(IntPtr.Zero, ... bla bla bla)
Marshal.StructureToPtr(idEnum, pidEnum, False)
' this also give me an error "Value can't be null"

I also tried:
Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr
Marshal.PtrToStructure(pidEnum, idEnum)
' this also give me an error "Value can't be null"
this is how I defined EnumObjects
<PreserveSig()> _
Function EnumObjects(ByVal hwnd As IntPtr, ByVal grfFlags As
COM.ShellAPI.SHCONTF, ByRef ppenumIDList As IntPtr) As Int32

what am I missing?

Thanks in advance
Nicola Garone


Nov 20 '05 #1
4 2237
This is what my implementation looks like - of course, it might not be
optimal, but EnumObjects should return a pointer to an IEnumIDList. If it
returns nothing, then the object is not enumerable and perhaps your
IShellFolder is not correct.

Public Shared Function GetIEnum(ByRef theFolder As COM.IShellFolder) As
COM.IEnumIDList

Dim ptrRet As IntPtr

' Get the pidl enumerator

theFolder.EnumObjects(IntPtr.Zero, COM.ShellAPI.SHCONTF.SHCONTF_FOLDERS,
ptrRet)

' if its null, we don't have an enumerator (we are not enumerable!)

If ptrRet.Equals(IntPtr.Zero) Then
Return Nothing
End If

' Get the shell enum type

Dim shellEnumType As System.Type =
System.Type.GetType("CR.COM.IEnumIDList")

' COM cast to an IEnumIDList

Dim obj As [Object] = Marshal.GetTypedObjectForIUnknown(CType(ptrRet,
IntPtr), shellEnumType)

' and cast to the interface

Return DirectCast(obj, COM.IEnumIDList)
End Function
"Nicola Garone" <ng*****@dimensionecad.it> wrote in message
news:u4**************@TK2MSFTNGP10.phx.gbl...
Hi all,
I need to enumerate pidl in a directory which I got (I think) the rigt
pidl, but I don't know how to procede.

here is a piece of code (folder is a IShellFolder object and it seems to
work correctly)

Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr
folder.EnumObjects(IntPtr.Zero, _
COM.ShellAPI.API.SHCONTF.SHCONTF_FOLDERS Or _
COM.ShellAPI.API.SHCONTF.SHCONTF_NONFOLDERS, _
pidEnum)

Now pidEnum got a value and this make me thind folder.EnumObjects works
well
but OF COURSE idEnum (which I must use) is Nothing since is not initialized so I can't use
Dim hRes As Integer
hRes = idEnum.Next(1, pidl, fetched)

I tried:
Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr =
Marshal.AllocHGlobal(Marshal.SizeOf(idEnum))
' this give me an error "Value can't be null"

I also tried:
Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr
folder.EnumObjects(IntPtr.Zero, ... bla bla bla)
Marshal.StructureToPtr(idEnum, pidEnum, False)
' this also give me an error "Value can't be null"

I also tried:
Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr
Marshal.PtrToStructure(pidEnum, idEnum)
' this also give me an error "Value can't be null"
this is how I defined EnumObjects
<PreserveSig()> _
Function EnumObjects(ByVal hwnd As IntPtr, ByVal grfFlags As
COM.ShellAPI.SHCONTF, ByRef ppenumIDList As IntPtr) As Int32

what am I missing?

Thanks in advance
Nicola Garone

Nov 20 '05 #2
This is what my implementation looks like - of course, it might not be
optimal, but EnumObjects should return a pointer to an IEnumIDList. If it
returns nothing, then the object is not enumerable and perhaps your
IShellFolder is not correct.

Public Shared Function GetIEnum(ByRef theFolder As COM.IShellFolder) As
COM.IEnumIDList

Dim ptrRet As IntPtr

' Get the pidl enumerator

theFolder.EnumObjects(IntPtr.Zero, COM.ShellAPI.SHCONTF.SHCONTF_FOLDERS,
ptrRet)

' if its null, we don't have an enumerator (we are not enumerable!)

If ptrRet.Equals(IntPtr.Zero) Then
Return Nothing
End If

' Get the shell enum type

Dim shellEnumType As System.Type =
System.Type.GetType("CR.COM.IEnumIDList")

' COM cast to an IEnumIDList

Dim obj As [Object] = Marshal.GetTypedObjectForIUnknown(CType(ptrRet,
IntPtr), shellEnumType)

' and cast to the interface

Return DirectCast(obj, COM.IEnumIDList)
End Function
"Nicola Garone" <ng*****@dimensionecad.it> wrote in message
news:u4**************@TK2MSFTNGP10.phx.gbl...
Hi all,
I need to enumerate pidl in a directory which I got (I think) the rigt
pidl, but I don't know how to procede.

here is a piece of code (folder is a IShellFolder object and it seems to
work correctly)

Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr
folder.EnumObjects(IntPtr.Zero, _
COM.ShellAPI.API.SHCONTF.SHCONTF_FOLDERS Or _
COM.ShellAPI.API.SHCONTF.SHCONTF_NONFOLDERS, _
pidEnum)

Now pidEnum got a value and this make me thind folder.EnumObjects works
well
but OF COURSE idEnum (which I must use) is Nothing since is not initialized so I can't use
Dim hRes As Integer
hRes = idEnum.Next(1, pidl, fetched)

I tried:
Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr =
Marshal.AllocHGlobal(Marshal.SizeOf(idEnum))
' this give me an error "Value can't be null"

I also tried:
Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr
folder.EnumObjects(IntPtr.Zero, ... bla bla bla)
Marshal.StructureToPtr(idEnum, pidEnum, False)
' this also give me an error "Value can't be null"

I also tried:
Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr
Marshal.PtrToStructure(pidEnum, idEnum)
' this also give me an error "Value can't be null"
this is how I defined EnumObjects
<PreserveSig()> _
Function EnumObjects(ByVal hwnd As IntPtr, ByVal grfFlags As
COM.ShellAPI.SHCONTF, ByRef ppenumIDList As IntPtr) As Int32

what am I missing?

Thanks in advance
Nicola Garone

Nov 20 '05 #3
Since also your code dind't work (on my pc) I supposed interface definition
and finally I discovered the value of SHCONTF_FOLDER was wrong, Sigh!!
Thanks a lot for your help. I'm afraid I'll need again for next steps :-)
Nicola.

"Robin Tucker" <id*************************@reallyidont.com> ha scritto nel
messaggio news:c5*******************@news.demon.co.uk...
This is what my implementation looks like - of course, it might not be
optimal, but EnumObjects should return a pointer to an IEnumIDList. If it
returns nothing, then the object is not enumerable and perhaps your
IShellFolder is not correct.

Public Shared Function GetIEnum(ByRef theFolder As COM.IShellFolder) As
COM.IEnumIDList

Dim ptrRet As IntPtr

' Get the pidl enumerator

theFolder.EnumObjects(IntPtr.Zero, COM.ShellAPI.SHCONTF.SHCONTF_FOLDERS, ptrRet)

' if its null, we don't have an enumerator (we are not enumerable!)

If ptrRet.Equals(IntPtr.Zero) Then
Return Nothing
End If

' Get the shell enum type

Dim shellEnumType As System.Type =
System.Type.GetType("CR.COM.IEnumIDList")

' COM cast to an IEnumIDList

Dim obj As [Object] = Marshal.GetTypedObjectForIUnknown(CType(ptrRet,
IntPtr), shellEnumType)

' and cast to the interface

Return DirectCast(obj, COM.IEnumIDList)
End Function
"Nicola Garone" <ng*****@dimensionecad.it> wrote in message
news:u4**************@TK2MSFTNGP10.phx.gbl...
Hi all,
I need to enumerate pidl in a directory which I got (I think) the rigt pidl, but I don't know how to procede.

here is a piece of code (folder is a IShellFolder object and it seems to
work correctly)

Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr
folder.EnumObjects(IntPtr.Zero, _
COM.ShellAPI.API.SHCONTF.SHCONTF_FOLDERS Or _
COM.ShellAPI.API.SHCONTF.SHCONTF_NONFOLDERS, _
pidEnum)

Now pidEnum got a value and this make me thind folder.EnumObjects works
well
but OF COURSE idEnum (which I must use) is Nothing since is not

initialized
so I can't use
Dim hRes As Integer
hRes = idEnum.Next(1, pidl, fetched)

I tried:
Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr =
Marshal.AllocHGlobal(Marshal.SizeOf(idEnum))
' this give me an error "Value can't be null"

I also tried:
Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr
folder.EnumObjects(IntPtr.Zero, ... bla bla bla)
Marshal.StructureToPtr(idEnum, pidEnum, False)
' this also give me an error "Value can't be null"

I also tried:
Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr
Marshal.PtrToStructure(pidEnum, idEnum)
' this also give me an error "Value can't be null"
this is how I defined EnumObjects
<PreserveSig()> _
Function EnumObjects(ByVal hwnd As IntPtr, ByVal grfFlags As
COM.ShellAPI.SHCONTF, ByRef ppenumIDList As IntPtr) As Int32

what am I missing?

Thanks in advance
Nicola Garone


Nov 20 '05 #4
Since also your code dind't work (on my pc) I supposed interface definition
and finally I discovered the value of SHCONTF_FOLDER was wrong, Sigh!!
Thanks a lot for your help. I'm afraid I'll need again for next steps :-)
Nicola.

"Robin Tucker" <id*************************@reallyidont.com> ha scritto nel
messaggio news:c5*******************@news.demon.co.uk...
This is what my implementation looks like - of course, it might not be
optimal, but EnumObjects should return a pointer to an IEnumIDList. If it
returns nothing, then the object is not enumerable and perhaps your
IShellFolder is not correct.

Public Shared Function GetIEnum(ByRef theFolder As COM.IShellFolder) As
COM.IEnumIDList

Dim ptrRet As IntPtr

' Get the pidl enumerator

theFolder.EnumObjects(IntPtr.Zero, COM.ShellAPI.SHCONTF.SHCONTF_FOLDERS, ptrRet)

' if its null, we don't have an enumerator (we are not enumerable!)

If ptrRet.Equals(IntPtr.Zero) Then
Return Nothing
End If

' Get the shell enum type

Dim shellEnumType As System.Type =
System.Type.GetType("CR.COM.IEnumIDList")

' COM cast to an IEnumIDList

Dim obj As [Object] = Marshal.GetTypedObjectForIUnknown(CType(ptrRet,
IntPtr), shellEnumType)

' and cast to the interface

Return DirectCast(obj, COM.IEnumIDList)
End Function
"Nicola Garone" <ng*****@dimensionecad.it> wrote in message
news:u4**************@TK2MSFTNGP10.phx.gbl...
Hi all,
I need to enumerate pidl in a directory which I got (I think) the rigt pidl, but I don't know how to procede.

here is a piece of code (folder is a IShellFolder object and it seems to
work correctly)

Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr
folder.EnumObjects(IntPtr.Zero, _
COM.ShellAPI.API.SHCONTF.SHCONTF_FOLDERS Or _
COM.ShellAPI.API.SHCONTF.SHCONTF_NONFOLDERS, _
pidEnum)

Now pidEnum got a value and this make me thind folder.EnumObjects works
well
but OF COURSE idEnum (which I must use) is Nothing since is not

initialized
so I can't use
Dim hRes As Integer
hRes = idEnum.Next(1, pidl, fetched)

I tried:
Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr =
Marshal.AllocHGlobal(Marshal.SizeOf(idEnum))
' this give me an error "Value can't be null"

I also tried:
Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr
folder.EnumObjects(IntPtr.Zero, ... bla bla bla)
Marshal.StructureToPtr(idEnum, pidEnum, False)
' this also give me an error "Value can't be null"

I also tried:
Dim idEnum As IEnumIDList
Dim pidEnum As IntPtr
Marshal.PtrToStructure(pidEnum, idEnum)
' this also give me an error "Value can't be null"
this is how I defined EnumObjects
<PreserveSig()> _
Function EnumObjects(ByVal hwnd As IntPtr, ByVal grfFlags As
COM.ShellAPI.SHCONTF, ByRef ppenumIDList As IntPtr) As Int32

what am I missing?

Thanks in advance
Nicola Garone


Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Melinda | last post by:
hi all, i'm having problems with BindToObject(). when i call the method it is throwing a System.NullReferenceException error, but i don't understand why. what i'm trying to do is get a...
0
by: Robin Tucker | last post by:
I need to create my own explorer-style control - I don't seem to have access to IShellFolder - assuming I need it (which I think I do), how can this be done? I've imported shell32.dll into my...
4
by: Robin Tucker | last post by:
I can't get this damned IEnumIDList thing to work correctly. I've got the desktop folder as an IShellObject (which I've verified by being able to get the display name etc. from it). I can also...
2
by: Robin Tucker | last post by:
I've got this nice pidl, enumerated via. IEnumIDList on an IShellFolder (the desktop). I know the pidl is ok, because I can list its display name and its looking good. Now I want to go a level...
2
by: Nicola Garone | last post by:
Hi all I'm using VB.net. I need to define an object of type iShellFolder (since I have to call ShGetDesktopfolder API in Shell32.dll). I've created interop.Shell32.dll adding a reference to...
4
by: Nicola Garone | last post by:
Hi all, I need to enumerate pidl in a directory which I got (I think) the rigt pidl, but I don't know how to procede. here is a piece of code (folder is a IShellFolder object and it seems to...
1
by: Nicola Garone | last post by:
Hi all, here I am again :-( , this turn I'm in trouble with IShellFolder.GetUIObjectsOf, which raise an exception while accessing an uninstantiated object (I have Italian version softwares and I...
1
by: Andrius B. | last post by:
Hi. My problem concerns vb .net 2005. I want to use IShellFolder interface for such functions as ParseDisplayname. But how to parse a string - folder name (I mean, adding terminating nullchar or...
2
by: Andrius B. | last post by:
Hi all. Does anyone can suggest a good webpage or site, where I could read about how to use IShellFolder interface in vb .net ? E.g., I have added reference to IShellFolderEx_TLB.dll, but what...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.