Link to home
Start Free TrialLog in
Avatar of ascot
ascot

asked on

cannot instantiate abstract class due to following members

I've created a COM component with 2 CoClasses Cbar and Cfoo.  I then add a property to Ibar, called foobar, specifying a Property type of Ifoo *.  Now normally if I defined a property of type int, long etc., when I did a build I would end up with
STDMETHODIMP Cbar::get_abcbar(short *pVal) { // TODO: Add your implementation code here  return S_OK; }

STDMETHODIMP Cbar::put_abcbar(short newVal) { // TODO: Add your implementation code here return S_OK;}
in bar.cpp.
However this doesn't happen when I add my property of type Ifoo*.  Consequently when I compile I get the error
"cannot instantiate abstract class due to following members"
:get_foobar(struct Ifoo ** )' : pure virtual function was not defined
etc.
 
Here is the IDL
      [
            object,
            uuid(1BB29A26-A096-4E00-B7B9-9B77B9B0B35D),
            dual,
            helpstring("Ifoo Interface"),
            pointer_default(unique)
      ]
      interface Ifoo : IDispatch
      {
      };
      [
            object,
            uuid(AB73E6E4-11B1-4182-AD07-01641772A1F0),
            dual,
            helpstring("Ibar Interface"),
            pointer_default(unique)
      ]
      interface Ibar : IDispatch
      {
            [propget, id(1), helpstring("property foobar")] HRESULT foobar([out, retval] Ifoo* *pVal);
            [propput, id(1), helpstring("property foobar")] HRESULT foobar([in] Ifoo* newVal);
      };
ASKER CERTIFIED SOLUTION
Avatar of rcarlan
rcarlan

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
Avatar of ascot
ascot

ASKER

Thanks for the input.  Tried again this morning to see if it was the order that I was creating my ATL objects that was causing the problem.
First of all did the following:-
Create project using ATL COM Wizard.
Create DLL.
Right click on Project folder - NEW ATL Object - Simple Object - Short Name "foo"
Right click on Project folder - NEW ATL Object - Simple Object - Short Name "bar"
In Class View, right click on Ibar and select "Add Property.  Specify Prperty Type as Ifoo*, Property Name foobar.

Every built ok.

So then tried

Create project using ATL COM Wizard.
Create DLL.
Right click on Project folder - NEW ATL Object - Simple Object - Short Name "bar"
Right click on Project folder - NEW ATL Object - Simple Object - Short Name "foo"
In Class View, right click on Ibar and select "Add Property.  Specify Prperty Type as Ifoo*, Property Name foobar.

When I build I get the error
error MIDL2025 : syntax error : expecting a type specification near "Ifoo"
error MIDL2026 : cannot recover from earlier syntax errors; aborting compilation  

so I edited the IDL file to move the Ifoo interface definition before the Ibar interface definition and everything built ok.  
So I am at a loss to understand why things failed previously.

But again thanks for a very clear response which did help me understand the problem.
I've been doing MFC and ATL programming for longer than I care to remember. OK, I'm going to admit it: I started with Visual C++ (that is, the first version, 16 bit, Win 3.1, back in 1993) and I've been doing it ever since. It doesn't get any longer than that :-)

Anyway, with the experience I have I can say this: the Wizards are great (at least the MFC Wizard, 'cause the ATL one is pretty useless;-) but you have to understand what it is that they do. There's no magic (despite the fact they're called Wizards:-). All they do is to insert code snippets. Once you understand exactly what code you get from them and under what circumstances, you become much better at using them (or not using them - as the case may be;-). You have to become comfortable with editing the code they generate, with typing the stuff in yourself, etc.

Documentation helps, searching on the NET, asking questions on Experts Exchange ;-) but the best tool is a source control system (even if it's a personal one, with the repository on your local machine). Check the files out, invoke a Wizard command, and do a "Show Differences". Doesn't get much clearer than that.

I'm sure you've already learned a lot about the ATL Wizard through this exercise. You had the right approach: follow a sequence of steps and analyse the results.

Good luck in your programming career.

Radu