views:

385

answers:

3

I have a COM Callable Wrapper that I'm using from a VB6 program, but the program won't receive COM events unless the CCW is registered. Otherwise, the CCW works fine, just no events until I remove the program's manifest file and register the CCW using "regasm /tlb /codebase theccw.dll". This is in WinXP SP3.

What could be the problem?

Maybe my CCW is built wrong for use as an "early bound" VB6 object. Here are my declarations:

[ComVisible(false)]
public delegate void AnEventDelegate(int arg1);

[
ComVisible(true),
GuidAttribute("XXXX-XXXX-XXXX-XXXX"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)
]
public interface IComEvents
{
    void AnEvent(int arg1);
}

[
ComVisible(true),
Guid("YYYY-YYYY-YYYY-YYYY"),
ClassInterface(ClassInterfaceType.None), 
ComSourceInterfaces(typeof(IComEvents))
]
public class TheComClass: IComContract
{
    public TheComClass(){}

    // Implicit implementation of IComContract.
    // Implicit implementation of IComEvents.
    // 
    // eg. public event AnEventDelegate AnEvent;
}

[
ComVisible(true),
Guid("ZZZZ-ZZZZ-ZZZZ-ZZZZ")
]
public interface IComContract
{
    [ComVisible(true)]
    string AProp{ get; set; }

    [ComVisible(true)]
    void AMethod();
}

One thing I just realized. I don't have [ComVisible(true)] attributes on my public event declarations inside of TheComClass. I don't think that's the problem because I do get the events when the thing is registered, but we'll see...

A: 

In COM events aren't early bound. Where events in .NET are just a specialised usage of the delegates and are ultimately just function calls, COM events are much more involved.

You will need the component registered for events to work.

AnthonyWJones
Do you know where I can read more about this?
wizlb
A: 

I had the same problem, and figured how to fix it.

Make your class derive from System.Windows.Forms.UserControl.

I have gotten a C# written COM server to use events from VB6, even with registration-free COM.

Apparently UserControl implements IOleObject, which is required for some cases.

Jonathan.Peppers
A: 

The only answer that I found is that this doesn't work and I must register the CCW.

wizlb