1

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.

2 Answers 2

0

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

var icon = Icon.FromHandle(pic.Handle);
2
  • 1
    I tried that--throws System.RuntimeInteropServices.COMException: Catastrophic failure Aug 28, 2009 at 12:47
  • Hi, did you find any solution for that? I get my error here: var pic = user.GetPicture(); (Catastrophic failure)
    – PernerOl
    Oct 6, 2015 at 19:14
0

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(iconHandle);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.