Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7503613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:17:17+00:00 2026-05-29T21:17:17+00:00

I have the following code : [DllImport(shell32.dll, CharSet = CharSet.Unicode, PreserveSig = false)] static

  • 0

I have the following code:

[DllImport("shell32.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
static extern void SHCreateItemFromParsingName(
[In][MarshalAs(UnmanagedType.LPWStr)] string pszPath,
[In] IntPtr pbc,
[In][MarshalAs(UnmanagedType.LPStruct)] Guid iIdIShellItem,
[Out][MarshalAs(UnmanagedType.Interface, IidParameterIndex = 2)] out IShellItem iShellItem);


[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")]
interface IShellItem
{
}

To use this function:

IShellItem iShellItem = null;
Guid iIdIShellItem = new Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe");
SHCreateItemFromParsingName(sourceFile, IntPtr.Zero, iIdIShellItem, out iShellItem);

It works great, and I use it to get OS icon bitmaps later. My question is:

Do I need to free any resource? Could some tell me how?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:17:19+00:00Added an answer on May 29, 2026 at 9:17 pm

    IShellItem is a COM interface. Your declaration of it with the [ComImport] attribute ensures that the CLR creates a wrapper for it, an RCW (Runtime Callable Wrapper). Which is a managed wrapper around the native interface. RCWs behave just like regular .NET classes, they are managed by the garbage collector. With the exact same rules, sooner or later the garbage collector sees that your program doesn’t have a reference to the RCW anymore. And puts in on the finalizer queue. The RCW’s finalizer calls the IUnknown::Release() method and that destroys the native COM object.

    In other words, it is automatic, just like .NET objects.

    You technically can hurry it along by calling Marshal.ReleaseComObject(). It is roughly equivalent to IDisposable.Dispose(), a method that RCWs don’t implement because it is so difficult to see indirect references on COM interface pointers. Using it is a good way to shoot your foot though, with misbehavior somewhere between it having no effect at all because you missed a reference and crashing your program with “COM object that has been separated from its underlying RCW cannot be used”. Just not needed for a simple shell item reference, especially when you consume it quickly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following declaration for SHChangeNotify : [DllImport(Shell32.dll)] public static extern void SHChangeNotify(HChangeNotifyEventID
I have the following code in my application: [DllImport(user32.dll)] private static extern int GetWindowLong(IntPtr
I have the following function: [DllImport(user32.dll, CharSet=CharSet.Auto)] static extern int SendMessage(IntPtr hWnd, int wMsg,
I have tried the following code but has no effect: Imports system.Runtime.InteropServices <DllImport(UxTheme.DLL, BestFitMapping:=False,
I am using Mono/C# on Linux and have the following C# code: [DllImport(libaiousb)] extern
im using the following method [DllImport(kernel32.dll, SetLastError=true)] static extern int GetProcessId(IntPtr hWnd); to try
I have the following C# code that uses DLLImport. using System; namespace LvFpga {
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I have following code in my application: // to set tip - photo in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.