错误C2146并不知道为什么 [英] error C2146 and do not know why

查看:86
本文介绍了错误C2146并不知道为什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我的应用程序中有一些我不明白的奇怪行为。

我的配置:VS2010,Win7



在我的VS解决方案中,我有一个项目TextControl,它包含4个用于不同ActiveX控件的基本包装类。包装器是由VS自动创建的。

另外还有一个主包装器类捆绑了另一个4.



这是一部分主包装器的代码(TextControl.h):



Hello,

I do have a strange behavior in my application that I do not understand.
My configuration: VS2010, Win7

In my VS solution I have a project "TextControl" which contains of 4 basic wrapper classes for different ActiveX Controls. The wrappers were created automatically by VS.
In addition there is one main wrapper class that bundles the other 4.

Here is a part of the main wrapper's code (TextControl.h):

#include <stdafx.h>
#include <HTString.h>
#include <CDTX4OLE.h>	//TX Text Control
#include <CDTXBBAR.h>	//TX Text Control Button Bar
#include <CDTXSBAR.h>	//TX Text Control Status Bar
#include <CDTXRULER.h>	//TX text Control Ruler

class TextControl : public CWnd
{
public:
	TextControl();
	~TextControl();

	BOOL Init(CWnd* parent,	const CRect& tcRect, DWORD tcOpt = WS_VISIBLE | WS_TABSTOP);

	HTString GetText();
	void SetText(HTString text);

protected:
	CDTX4OLE m_txCtrl;		//@cmember TX Text Control 
	CDTXBBAR m_txBBar;		//@cmember TX Text Control Button Bar 
	CDTXSBAR m_txSBar;		//@cmember TX Text Control Status Bar 
	CDTXRULER m_txRuler;		//@cmember TX Text Control Ruler 

private:
};





所以主包装器拥有一个接口到每个4个包装。项目编译没有任何错误。但是当我编译另一个使用TextControl的项目时,我收到错误C2146与C4430一起



错误发生在以下代码中的上述代码中:





So the main wrapper owns an interface to each of the 4 wrappers. The project compiles w/o any error. But when I compile another project that makes use of "TextControl" then I receive the error C2146 in combination with C4430

The error occurs in above code in the following line:

CDTXBBAR m_txBBar;		//@cmember TX Text Control Button Bar





告诉我CDTXBBAR没有定义。我不知道为什么因为定义TextControl的项目没有编译任何错误。

如果我评论这一行,根本没有错误 - 在TextControl项目和使用的项目中都没有TextControl。这让我觉得CDTXBBAR有问题但是无法理解。



这是CDTXBAR.h和.cpp的内容





and tells me that CDTXBBAR is not defined. I do not know why since the project that defines the TextControl compiles w/o any error.
If I comment this line there is no error at all - neither in the TextControl project nor in the one that uses the TextControl. This lets me think that there is something wrong with CDTXBBAR but can't figure it out.

Here is the content of CDTXBAR.h and .cpp

// CDTXBBAR.h  : Declaration of ActiveX Control wrapper class(es) created by Microsoft Visual C++

#pragma once

/////////////////////////////////////////////////////////////////////////////
// CDTXBBAR

class CDTXBBAR : public CWnd
{
protected:
    DECLARE_DYNCREATE(CDTXBBAR)
public:
    CLSID const& GetClsid()
    {
    	static CLSID const clsid 
            = { 0xA8EF909, 0x46E5, 0x11E3, { 0xA5, 0x45, 0x0, 0x13, 0xD3, 0x50, 0x66, 0x7C } };
    	return clsid;
    }

    virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle,
			const RECT& rect, CWnd* pParentWnd, UINT nID, 
			CCreateContext* pContext = NULL)
    { 
    	return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); 
    }
    
    BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, 
		UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE,
		BSTR bstrLicKey = NULL)
    { 
    	return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
    	pPersist, bStorage, bstrLicKey); 
    }
    
    // Attributes
    public:
    
    // Operations
    public:
    
    unsigned long get_DisplayColor(long index)
    {
    	unsigned long result;
    	static BYTE parms[] = VTS_I4 ;
    	InvokeHelper(0x1b, DISPATCH_PROPERTYGET, VT_UI4, (void*)&result, parms, index);
    	return result;
    }

    void put_DisplayColor(long index, unsigned long newValue)
    {
    	static BYTE parms[] = VTS_I4 VTS_UI4 ;
    	InvokeHelper(0x1b, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, index, newValue);
    }

    void AboutBox()
    {
    	InvokeHelper(DISPID_ABOUTBOX, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
    }   
};







// CDTXBBAR.cpp  : Definition of ActiveX Control wrapper class(es) created by Microsoft Visual C++


#include "stdafx.h"
#include "CDTXBBAR.h"

/////////////////////////////////////////////////////////////////////////////
// CDTXBBAR

IMPLEMENT_DYNCREATE(CDTXBBAR, CWnd)

// CDTXBBAR properties

// CDTXBBAR operations





我已经比较了其他自动生成的包装器,但没有区别。



I already compared the other automatically generated wrappers with this one, but there is no difference.

推荐答案

几个想法:

- 你有' #include< stdafx.h>',这几乎肯定是一个错误。这包括应该只在.cpp文件中。这可能是也可能不是错误的来源。

- 您可能有一个重复的类定义。转到发生错误的.c​​pp文件,右键单击include行上的CDTXBBAR.h,打开文件并确保它包含您认为包含的内容。

- 如果您使用你的.h文件中的#ifdef BLAHBLAH防护块,确保每个魔术字符串都是唯一的(每个文件)......或者只是删除它们,只需使用#pragma一次。

- 确保你没有在你的另一个头文件中做过像#define CDTXBBAR或#define CDTXBBAR CDTXBBAR blah这样的哑巴。
Several thoughts:
- You have '#include <stdafx.h>', which is almost certainly an error. This include should be in .cpp files only. This may or may not be the source of the error.
- You may have a duplicate definition of the class. Go to the .cpp file where the error occurs, right click the "CDTXBBAR.h" on the include line, open the file and make sure it contains what you think it contains.
- If you use the "#ifdef BLAHBLAH" guard blocks in your .h files, make sure that each magic string is unique (per file) ... or just get rid of them and simply use #pragma once.
- Make sure you haven't done something dumb like "#define CDTXBBAR " or "#define CDTXBBAR CDTXBBAR blah" in another of your header files.


这篇关于错误C2146并不知道为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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