Returning icon handle to VCSharp

I have written a DLL using VC++ Express, in it I export the following function:


Answer this question

Returning icon handle to VCSharp

  • Nikhil Pereira

    If you're using a global mouse hook, I'm assuming the window handle that of a window in another application If that's the case, most handles are application-specific. Retreiving a handle via a SendMessage call will get an application-specific handle. The HICON from the SHGetFileInfo should work.

    Handles are usually just a pointer into the application's memory--which generally isn't accessible by other applications. You have to marshal the handle from one process to another. I don't know of any Platform SDK functions that would marshal an icon handle from one process to another. I think you'd have to spawn a thread in the source process to get the icon data and communicate it back to the other process. Not a trivial process.



  • Glenn Peterson

    Ok, I removed everything except the code to get the icon via SHGetFileInfo and am getting the same results. Any ideas
  • Do Hoang Ha

    What does your DllImport statement look like in your C# program. Also, how are you getting the myHwnd value

  • Labi

    [DllImport("apihooks.dll", CharSet = CharSet.Auto,

    CallingConvention = CallingConvention.StdCall)]

    public static extern IntPtr GetWindowIcon(IntPtr hwnd, IntPtr hicon);

  • Returning icon handle to VCSharp