3
votes

I have an interface (ITask) that implemented by a VB6 COM object. I have a C++ COM object that uses the interface, and it generally works fine.

However, when I run the VB6 debugger to debug the VB6 COM object, my C++ object is all of a sudden getting E_NOINTERFACE returned when it calls QueryInterface on the VB6 object for the ITask interface.

Interface definition:

[
    object,
    uuid(XXXX),
    pointer_default(unique),
    oleautomation
]

interface ITask : IUnknown
{
        [id(1)] HRESULT CreateTask([in, string] BSTR taskName);
}

C++ code: hResult = pDisp->QueryInterface(IID_ITask, (void **) &m_pTaskApp);

(pDisp is an IDispatch * to the VB6 COM object that I obtained through a call to a different component that manages object lifetimes)

A call to QueryInterface for IID_IDispatch succeeds when the VB6 COM object is running the debugger.

Any ideas?

EDIT - Add the VB6 code:

Implements ITask

Private Sub ITask_CreateTask(ByVal taskName as String)
    ' do stuff
End Sub
1
Is this a class or a user control in VB6 that you are instantiating?wqw

1 Answers

1
votes

Your description suggests that your VB6 component does contain your class (CLSID) but that when debugging you don't get a component that implements the same interface as your compiled version.

This is probably due to your compatibility settings in your VB6 COM component. You can change them in Project Properties->Component in VB6.

The default setting is "Project compatibility". When you choose this option, then each new version of your component will use the same class ID (CLSID) but get a new interface ID. This happens even though all your public functions and properties are the same as in the previous version. Note that this happens both when you compile your project and when you restart it in Debug mode. See http://support.microsoft.com/kb/161137 for description of the compatibility modes.

To solve your problem, set the compatibility mode to Binary Compatibility.