none
How to call RegisterObjectParam of IBindCtx? RRS feed

  • Question

  • I met a problem when developing an folder-browsing app by shell. The sub folder of network folder can not be retrieved sometimes. According to debug result I find that it failed to get the IShellFolder of network folder.

    And here is my code:

    Int hres = desktopShellFolders.BindToObject(idList, IntPtr.Zero, ref iIdIShellFolder, out iNewShell);

    Here, idList is the PIDL of network folder.

     

    I searched from msdn and luckily got some info which seemed useful to my problem.

    Here is the link :

    ---------------------------------------------------------------------------------------------------------------

    http://msdn2.microsoft.com/en-us/library/bb762592(VS.85).aspx
    Bind Context String Keys
    Used by method IBindCtx::RegisterObjectParam to specify a bind context.

    STR_BIND_FORCE_FOLDER_SHORTCUT_RESOLVE 
    A folder shortcut is a folder item in the namespace that points to another folder item in the namespace using a link (shortcut) to hold the IDList of the target. The shortcut is resolved to track the target in case it is moved or renamed. For instance, the Windows XP My Network Places  folder and the Windows Vista Computer folder can contain folder shortcuts created with the Add Network Location wizard. The normal IShellFolder::BindToObject operations for folder shortcuts do not resolve links to network folders to improve performance. The presence of this bind context enables the folder shortcut to resolve the link that points to its target and is useful where being able to track the target is worth the performance implications of resolving the target.

    ---------------------------------------------------------------------------------------------------------------

     

    I think I should create an IBindCtx instance and set it to the second parameter of BintToObject instead of IntPtr.Zero.

    But, I really can not get any info about how to call RegisterObjectParam and how to use STR_BIND_FORCE_FOLDER_SHORTCUT_RESOLVE.

     

    Is there anyone who can help me? Thank you very much

    Tuesday, March 4, 2008 10:18 AM

Answers

  • Teh IBindCtx interface is defined in the System.Runtime.InteropServices.ComTypes namespace. You can create an object that implements it using CreateBindCtx.

     

    Tuesday, March 4, 2008 3:03 PM
    Moderator

All replies

  • Teh IBindCtx interface is defined in the System.Runtime.InteropServices.ComTypes namespace. You can create an object that implements it using CreateBindCtx.

     

    Tuesday, March 4, 2008 3:03 PM
    Moderator
  •  

    Thank you very much for your reply.

    I think I did not describe what I realy want to know. Actually I have known the way to create IBindCtx. But how to set the parameter?  read the summary of RegisterObjectParam but still not understand. According to my context, could you please show me what parameter should be set? Thank you very much.

    Wednesday, March 5, 2008 1:29 AM
  • In ShObjIdl.idl from the Windows SDK you can find that the STR_BIND_FORCE_FOLDER_SHORTCUT_RESOLVE constant is defined as "Force Folder Shortcut Resolve". You can also see in the comments that the object doesn't have to support any particular interface (i.e. you can pass in any object, it's the presence of the key that matters).

     

    So I guess you'd call it like this

     

    const string STR_BIND_FORCE_FOLDER_SHORTCUT_RESOLVE = "Force Folder Shortcut Resolve";

    ...

    yourBindCtx.RegisterObjectParam(STR_BIND_FORCE_FOLDER_SHORTCUT_RESOLVE, new object());

     

    You then have to change your declaration of IShellFolder.BindToObject so that the second parameter is of type IBindCtx instead of IntPtr.

     

    Wednesday, March 5, 2008 12:31 PM
    Moderator
  •  

    Thank you very much for your reply. But it does not work

    I still can not get the iNewShell, the return result of BindToObject is always 1, which flags that the method failed. And the out value iNewShell is NULL.

    Do you have any idea about  it? Thank you very much.

    Friday, March 7, 2008 1:39 AM