ATL COM与visual studio 03 [英] ATL COM with visual studio 03

查看:83
本文介绍了ATL COM与visual studio 03的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我是编程新手,并且正在尝试按照软件开发工具包实现ATL COM服务器。但是,我遇到了各种各样的问题。 Iv创建了一个ATL项目并添加了一个名为CoSensorServer的简单对象。然后我实现了接口:



IPMSensorServer,

IPMSensorConfig,

IPMPositionGenerator

和IPMSensorRuntime


来自SDK中包含的库的




我的CoSensorServer cpp文件如下所示:



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)





编译时出现以下错误:< br $>




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 />





我有什么想法可以克服这个错误?我花了太多时间无济于事。非常感谢提前。



Andre



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

Andre

推荐答案

我已经做了很长时间了C ++,但编译器生成的第一个错误应该是你的第一个线索。您的类CoSensorServer在某种程度上是一个抽象类,您无法实例化一个抽象类。您*必须*从中派生一个新类并提供所需的纯虚方法。
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.


您必须实现接口的所有纯虚函数 class派生自。

:)
You've to implement all the pure virtual functions of the interfaces your class derive from.
:)


Arg我带着同样的问题绕圈子走了。我知道这已经太晚了几年,但是如果我发布我的答案,它仍然可以帮助其他人



事实证明我在我的IDL界面中指定了IDispatchEx而不是IDispatch宣言。一个愚蠢的复制/粘贴错误。



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.

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


这篇关于ATL COM与visual studio 03的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆