Results 1 to 3 of 3

Thread: CoTaskMemFree vs ILFree

  1. #1

    Thread Starter
    Lively Member vbLewis's Avatar
    Join Date
    Feb 2009
    Location
    USA
    Posts
    126

    CoTaskMemFree vs ILFree

    Is anyone else having problems with CoTaskMemFree() crashing the IDE recently when trying to free ITEMIDLIST's?
    I have code that i have been using for years is all of a sudden not working on updated Win 10 with no change to the code. Calling cotaskmemfree closes the IDE but ILFree() works fine.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: CoTaskMemFree vs ILFree

    I'd almost expect the opposite behavior. Per MSDN: "Note When using Windows 2000 or later, use CoTaskMemFree rather than ILFree."

    For now, ignore that fact that it was working before. Look at each case you are calling CoTaskMemFree and ensure you are passing the memory address ByVal or ByRef dependent on how you declared the API.

    Try to create an example that will crash on demand and post that example here.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,647

    Re: CoTaskMemFree vs ILFree

    Definitely want to be using CoTaskMemFree.

    How exactly are you using id lists? If you're creating the structure and doing manual operations on them, there's a lot more room for issues; especially depending on how you're allocating it.

    If you're using pidls allocated and managed by the system, such that you're only ever dealing with a Long containing a pointer to it, you'd generally use it declared with ByVal and just pass the pointer itself, not a pointer to the pointer.

    E.g. if you're using a pidl as a long returned from ILCreateFromPath or SHGetFolderLocation, you'd have Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long), then
    Dim pidl As Long
    pidl = ILCreateFromPath(path)

    ...
    CoTaskMemFree pidl

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width