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))

3
  • 2
    If you don't have a really good reason to write your own wrapper you should create an automatic wrapper. Either by importing a COM reference in Visual Studio or creating the wrapper by tlbimp.exe Commented Aug 18, 2011 at 12:08
  • Agreed; it's just that I can't find any .tlb file which contains IStkCustomControl (another mystery). Commented Aug 18, 2011 at 12:13
  • That's because it is not an automation compatible interface that derives from IDispatch. Which makes using it from a managed program perilous. You'll have to redeclare the COM interfaces in your C# code. Commented Aug 18, 2011 at 15:33

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.