views:

262

answers:

2

I have a COM object (VB6 ActiveX exe) that returns a stdole.StdPicture through interop. Is there a way to convert that to a System.Drawing.Icon? Or is there a better return type for my COM object to return?

What I'm trying to do is have my C# code use an icon from my VB6 code.

A: 

If the Type of the StdPicture is vbPicTypeIcon then you can call:

var icon = Icon.FromHandle(pic.Handle);
Shay Erlichmen
I tried that--throws System.RuntimeInteropServices.COMException: Catastrophic failure
C-Pound Guru
A: 

Well, through trial and error I found the solution.

In the VB6 code, return the icon handle instead of the icon (the return type for Icon.Handle is OLE_HANDLE which can be returned as a long.

In the VB6 code:

Public Function GetIconHandle() as long

     GetIconHandle = myForm.Icon.Handle

End Function

In the .NET code:

IntPtr iconHandle = (IntPtr)COMDll.GetIconHandle(); // returns an int for the handle to the icon.
Icon myIcon = Icon.FromHandle(icnoHandle);
C-Pound Guru