Link to home
Start Free TrialLog in
Avatar of jasonclarke
jasonclarke

asked on

ATL Problems - adding a method to an interface

I have a COM object, written using ATL.  I am trying to add a new method to one of the interfaces, using the ATL 'Add Method' wizard.

It all appears to work fine, the server compiles and builds correctly.

However, whenever I call the new method from a client (VB or C++), I get an 0x80010105 error returned (This translates to The Server threw an Exception).  

My own code is never actually executed, the error is returned by COM before reaching my code.

Has anybody got any suggestions as to where I might look to work out what is going on?
Avatar of peterdownes
peterdownes

Unload the type libaray in VB and re-associate it (I can't remember the VB terms for this).

VB may be using the previous TLB info.

Regards.
Avatar of jasonclarke

ASKER

I don't think this is the case (I wrote a simple C++ client to eliminate some of these difficulties - and have deleted any other tlbs from the system).

VB & C++ can see the new method name in the tlb but for some reason it cannot call it.
Can you post the IDL?
I could post it, but it is quite long.  I will post the details of the relevant interface:

the interface definition:

    [
       object,
       uuid(7D1FC303-9AA2-11D4-B98C-A76022CF093A),
       dual,
       helpstring("IWellhead Interface"),
       pointer_default(unique)
    ]
    interface IWellhead : IDispatch
    {
       [propget, id(1), helpstring("property Name")] HRESULT Name([out, retval] BSTR *pVal);
       [id(2), helpstring("method GetSourcePricesAndCosts")] HRESULT GetSourcePricesAndCosts([out,retval] ISourcePriceCost** spc);
       [id(3), helpstring("method Import")] HRESULT Import();
       [id(4), helpstring("method ImportFile")] HRESULT ImportFile([in] BSTR wflFilePath);
       [id(5), helpstring("method TestingTesting")] HRESULT TestingTesting();
    };

and the associate coclass definition:

    [
        uuid(7D1FC304-9AA2-11D4-B98C-A76022CF093A),
        helpstring("WellHead Class"),
        noncreatable
    ]
    coclass Wellhead
    {
        [default] interface IWellhead;
    };


I don't think there is a problem with the IDL.  The new method (TestingTesting) is the only one that fails.  Everything else works perfectly.
How do you use it ?
If you didn't create the COM object as Dual Interface and you use it from VB latebinding, or import than it would not work...so make sure you have dual interface for such a call. Also are you using DCOM ?
There is no late binding, and DCOM is not involved.

Here is the simple C++ test client:

int main()
{
    CoInitialize(NULL);

    try
    {
        IReOIntegrationInterfacePtr p(__uuidof(ReOIntegrationInterface));

        p->OpenDatabase(_T("D:\\Phase3Clean\\Projects\\master network comp.reo"));

        ISnapshotPtr ss = p->GetSnapshot(_T("Initial"));

        IWellheadManagerPtr whm = ss->CreateWellheadManager();

        IWellheadPtr wh = whm->GetWellhead(whm->GetWellheadNames()->GetItem(0));

        _bstr_t name = wh->GetName();;

        wh->TestingTesting();
    }
    catch (_com_error& err)
    {
        _bstr_t desc = err.Description();
    }

    CoUninitialize();

    return 0;
}

Everything works just fine until the call to TestingTesting.
ASKER CERTIFIED SOLUTION
Avatar of snoegler
snoegler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Your comment lead me to the answer.  The problem was due to having a screwed up vtable.

The problem was caused because during a recent source code re-organisation I inadvertantly copied the compiler generated Server.h file into the project 'include' directory.  This file does of course determine the structure of the interface vtables.

What this meant was that I had two copies of the header file, one compiler generated and another representing some older state of the system.  The compiler generated version was being picked up for the tlb generation and the other one was being picked up for building the server.  (So the tlb looked correct - VB could see the new method), but the vtable was not including the new method hence the server exception.

Thanks for your help.
Thanks
Jason,

   I seem to have lost your e-mail address.  I just wanted to say thanks for your support.  I appreciate that.