Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Im new to programming and am attempting to implement an ATL COM server following a software development kit. However, I am having all sorts of problems. Iv created an ATL project and added a simple object called CoSensorServer. Iv then implemented interfaces:

IPMSensorServer,
IPMSensorConfig,
IPMPositionGenerator
and IPMSensorRuntime

from a library included in the SDK.

My CoSensorServer cpp file looks like this:

// CoSensorServer.cpp : Implementation of CCoSensorServer

#include "stdafx.h"
#include "CoSensorServer.h"


// CCoSensorServer

class ATL_NO_VTABLE CCoSensorServer : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CCoSensorServer, &CLSID_CoSensorServer>,
	public ICoSensorServer,
	public IPMPositionGenerator,
	public IPMSensorConfig,
	public IPMSensorRuntime,
	public IPMSensorServer
{
public:
	CCoSensorServer()
	{
	}

	DECLARE_REGISTRY_RESOURCEID(IDR_COSENSORSERVER)

	DECLARE_NOT_AGGREGATABLE(CCoSensorServer)

	BEGIN_COM_MAP(CCoSensorServer)
		COM_INTERFACE_ENTRY(ICoSensorServer)
		COM_INTERFACE_ENTRY(IPMPositionGenerator)
		COM_INTERFACE_ENTRY(IPMSensorConfig)
		COM_INTERFACE_ENTRY(IPMSensorRuntime)
		COM_INTERFACE_ENTRY(IPMSensorServer)
	END_COM_MAP()


	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease() 
	{
	}

public:


	// IPMPositionGenerator Methods
public:
	STDMETHOD(CreatePosGen)(GUID PosGenId, GUID SensorId, long * plType)
	{
		return E_NOTIMPL;
	}
	STDMETHOD(ConfigurePosGen)(GUID PosGenId, GUID SensorId, signed char * pbChanged)
	{
		return E_NOTIMPL;
	}
	STDMETHOD(RemovePosGen)(GUID PosGenId)
	{
		return E_NOTIMPL;
	}
	STDMETHOD(LoadPosGen)(GUID PosGenId, long lType, long lSize, unsigned char * pucBuffer, signed char * pbUpgraded)
	{
		return E_NOTIMPL;
	}
	STDMETHOD(SavePosGen)(GUID PosGenId, long * plSize, unsigned char * * ppucBuffer)
	{
		return E_NOTIMPL;
	}

	// IPMSensorConfig Methods
public:
	STDMETHOD(InitServer)()
	{
		return E_NOTIMPL;
	}
	STDMETHOD(CreateSensor)(GUID SensorId)
	{
		return E_NOTIMPL;
	}
	STDMETHOD(ConfigureSensor)(GUID SensorId, signed char * pbChanged)
	{
		return E_NOTIMPL;
	}
	STDMETHOD(RemoveSensor)(GUID SensorId)
	{
		return E_NOTIMPL;
	}
	STDMETHOD(LoadSensor)(GUID SensorId, long lSize, unsigned char * pucBuffer, signed char * pbUpgraded)
	{
		return E_NOTIMPL;
	}
	STDMETHOD(SaveSensor)(GUID SensorId, long * plSize, unsigned char * * ppucBuffer)
	{
		return E_NOTIMPL;
	}
	STDMETHOD(ShowStatus)(GUID SensorId)
	{
		return E_NOTIMPL;
	}

	// IPMSensorRuntime Methods
public:
	STDMETHOD(StartSensor)(GUID SensorId, long lGenerators, GUID * pPosGenerators, _IPMSensorResult * p_IPMSensorResult)
	{
		return E_NOTIMPL;
	}
	STDMETHOD(StopSensor)(GUID SensorId)
	{
		return E_NOTIMPL;
	}
	STDMETHOD(ShowRuntimeInfo)(GUID SensorId, signed char bShow)
	{
		return E_NOTIMPL;
	}

	// IPMSensorServer Methods
public:
	STDMETHOD(GetName)(BSTR * bstrName)
	{
		return E_NOTIMPL;
	}
	STDMETHOD(GetDescription)(BSTR * bstrDescription)
	{
		return E_NOTIMPL;
	}
	STDMETHOD(GetVersion)(long * plMajor, long * plMinor)
	{
		return E_NOTIMPL;
	}
};

OBJECT_ENTRY_AUTO(__uuidof(CoSensorServer), CCoSensorServer)


I am getting the following error when compiling:

c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlcom.h(1760): error C2259: 'ATL::CComObject<Base>' : cannot instantiate abstract class<br />
        with        [            Base=CCoSensorServer        ]<br />
<br />
<br />
<br />
<br />
The output:<br />
<br />
Rebuild All started: Project: MySensorServer, Configuration: Debug Win32 ------<br />
<br />
Deleting intermediate files and output files for project 'MySensorServer', configuration 'Debug|Win32'.<br />
Creating Type Library...<br />
Processing .\MySensorServer.idl<br />
MySensorServer.idl<br />
Processing C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\oaidl.idl<br />
oaidl.idl<br />
Processing C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\objidl.idl<br />
objidl.idl<br />
Processing C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\unknwn.idl<br />
unknwn.idl<br />
Processing C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\wtypes.idl<br />
wtypes.idl<br />
Processing C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\basetsd.h<br />
basetsd.h<br />
Processing C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\guiddef.h<br />
guiddef.h<br />
Processing C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\ocidl.idl<br />
ocidl.idl<br />
Processing C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\oleidl.idl<br />
oleidl.idl<br />
Processing C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\servprov.idl<br />
servprov.idl<br />
Processing C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\urlmon.idl<br />
urlmon.idl<br />
Processing C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\msxml.idl<br />
msxml.idl<br />
Processing C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\oaidl.acf<br />
oaidl.acf<br />
Processing C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\include\ocidl.acf<br />
ocidl.acf<br />
Compiling...<br />
stdafx.cpp<br />
Compiling...<br />
CoSensorServer.cpp<br />
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlcom.h(1760) : error C2259: 'ATL::CComObject<Base>' : cannot instantiate abstract class<br />
        with<br />
        [<br />
            Base=CCoSensorServer<br />
        ]<br />
        due to following members:<br />
        'HRESULT IPMPositionGenerator::ConfigurePosGen(GUID,GUID,char *)' : pure virtual function was not defined<br />
        c:\Documents and Settings\Andre Bedon\My Documents\Visual Studio Projects\MySensorServer\Debug\externalsensor.tlh(102) : see declaration of 'IPMPositionGenerator::ConfigurePosGen'<br />
        'HRESULT IPMPositionGenerator::LoadPosGen(GUID,long,long,unsigned char *,char *)' : pure virtual function was not defined<br />
        c:\Documents and Settings\Andre Bedon\My Documents\Visual Studio Projects\MySensorServer\Debug\externalsensor.tlh(108) : see declaration of 'IPMPositionGenerator::LoadPosGen'<br />
        'HRESULT IPMSensorConfig::ConfigureSensor(GUID,char *)' : pure virtual function was not defined<br />
        c:\Documents and Settings\Andre Bedon\My Documents\Visual Studio Projects\MySensorServer\Debug\externalsensor.tlh(73) : see declaration of 'IPMSensorConfig::ConfigureSensor'<br />
        'HRESULT IPMSensorConfig::LoadSensor(GUID,long,unsigned char *,char *)' : pure virtual function was not defined<br />
        c:\Documents and Settings\Andre Bedon\My Documents\Visual Studio Projects\MySensorServer\Debug\externalsensor.tlh(78) : see declaration of 'IPMSensorConfig::LoadSensor'<br />
        'HRESULT IPMSensorRuntime::ShowRuntimeInfo(GUID,char)' : pure virtual function was not defined<br />
        c:\Documents and Settings\Andre Bedon\My Documents\Visual Studio Projects\MySensorServer\Debug\externalsensor.tlh(184) : see declaration of 'IPMSensorRuntime::ShowRuntimeInfo'<br />
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlcom.h(1752) : while compiling class-template member function 'HRESULT ATL::CComCreator<T1>::CreateInstance(void *,const IID &,LPVOID * )'<br />
        with<br />
        [<br />
            T1=ATL::CComObject<CCoSensorServer><br />
        ]<br />
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlcom.h(1832) : see reference to class template instantiation 'ATL::CComCreator<T1>' being compiled<br />
        with<br />
        [<br />
            T1=ATL::CComObject<CCoSensorServer><br />
        ]<br />
        c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\atlcom.h(1828) : while compiling class-template member function 'HRESULT ATL::CComCreator2<T1,T2>::CreateInstance(void *,const IID &,LPVOID * )'<br />
        with<br />
        [<br />
            T1=ATL::CComCreator<ATL::CComObject<CCoSensorServer>>,<br />
            T2=ATL::CComFailCreator<-2147221232><br />
        ]<br />
        c:\Documents and Settings\Andre Bedon\My Documents\Visual Studio Projects\MySensorServer\CoSensorServer.cpp(135) : see reference to class template instantiation 'ATL::CComCreator2<T1,T2>' being compiled<br />
        with<br />
        [<br />
            T1=ATL::CComCreator<ATL::CComObject<CCoSensorServer>>,<br />
            T2=ATL::CComFailCreator<-2147221232><br />
        ]<br />
MySensorServer.cpp<br />
Generating Code...<br />
<br />
Build log was saved at "file://c:\Documents and Settings\Andre Bedon\My Documents\Visual Studio Projects\MySensorServer\Debug\BuildLog.htm"<br />
MySensorServer - 1 error(s), 0 warning(s)<br />
<br />
<br />
------ Skipped Rebuild All: Project: MySensorServerPS, Configuration: Debug Win32 ------<br />
<br />
Project configuration skipped because it is not selected in this solution configuration<br />
<br />
<br />
---------------------- Done ----------------------<br />
<br />
    Rebuild All: 0 succeeded, 1 failed, 1 skipped<br />


Any ideas how I can overcome this error? Iv spent too many hours to no avail. Thanks very much in advance.

Andre
Posted
Updated 13-Jan-10 2:31am
v2

It's been a long time sice I've done C++, but the very first error the compiler generates should be your first clue. Your class CoSensorServer is somehow an abstract class and you can't instantiate an abstract class. You *must* derive a new class from it and supply the required pure virtual methods.
 
Share this answer
 
You've to implement all the pure virtual functions of the interfaces your class derive from.
:)
 
Share this answer
 
Arg I went around in circles with this same problem. I know it's several years too late, but it still might help someone else if I post my answer

It turns out I had specified IDispatchEx instead of IDispatch in my IDL interface declaration. A silly copy/paste error.

idl
[
    object,
    uuid( ... ),
    dual,
    nonextensible,
    pointer_default(unique)
]
interface IMyHelper : IDispatchEx {   <-- OOPS!
    ...
};
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900