My first COM import

4

I have a .h file with the following declarations:

////////////////////////////////////////////////////////////////////////////////
// Syntek Plug-In Custom Control GUIDs.                                       //
////////////////////////////////////////////////////////////////////////////////
// {59DF6360-6F14-4472-82B6-6EAB971EEFAD}
DEFINE_GUID(CLSID_IStkCustomControl,
            0x59DF6360, 0x6F14, 0x4472, 0x82, 0xB6, 0x6E, 0xAB, 0x97, 0x1E, 0xEF, 0xAD);

// {59DF6361-6F14-4472-82B6-6EAB971EEFAD}
DEFINE_GUID(CLSID_IStkCustomControl_PropertyPage,
            0x59DF6361, 0x6F14, 0x4472, 0x82, 0xB6, 0x6E, 0xAB, 0x97, 0x1E, 0xEF, 0xAD);

// Custom Control Interfaces.
MIDL_INTERFACE("59DF6360-6F14-4472-82B6-6EAB971EEFAD")
IStkCustomControl : public IUnknown
{
public:
    virtual HRESULT STDMETHODCALLTYPE Get(PKSPROPERTY_STK_CUSTOM_CONTROL_S pStkCustomControl) = 0;
    virtual HRESULT STDMETHODCALLTYPE Set(PKSPROPERTY_STK_CUSTOM_CONTROL_S pStkCustomControl) = 0;
};

I would like to port the interface IStkCustomControl to C#. So far, I have this C# code:

Guid guid = new Guid(0x59df6360, 0x6f14, 0x4472, 0x82, 0xb6, 0x6e, 0xab, 0x97, 0x1e, 0xef, 0xad);
Type type = Type.GetTypeFromCLSID(guid); // line 2 
object obj = Activator.CreateInstance(type);

When executing line 2, I get the exception

Creating an instance of the COM component with CLSID {59DF6360-6F14-4472-82B6-6EAB971EEFAD} from the IClassFactory failed due to the following error: 80040202.

What's going wrong here?

UPDATE: I found out that the IStkCustomControl interface is implemented in a file called StkProp.ax. I've tried to run AxImp.exe StkProp.ax, but that gave me

AxImp Error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY))

c#
com-interop
asked on Stack Overflow Aug 18, 2011 by user181813 • edited Aug 18, 2011 by user181813

1 Answer

1

More often than not, the type info is embedded in the DLL that implements the object. Use OLEView to make sure. If so, then set up a COM reference to that DLL and use the auto wrapper.

Having the type info as standalone TLB file is so late nineties.

answered on Stack Overflow Aug 18, 2011 by Seva Alekseyev

User contributions licensed under CC BY-SA 3.0