Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
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):

C++
#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:
};


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:

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


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

C++
// 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);
    }   
};


C++
// 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.
Posted
Comments
OriginalGriff 11-Dec-13 9:51am    
What happens if you change the order of statements? Try putting the protected section above the public - it won't cure the problem, but it might move it to a different line, which might indicate which line is actually generating the problem.
DFaeuster 11-Dec-13 9:55am    
I changed the order of the public and protected block but still the same errors that are pointing to the line with CDTXBBAR m_txBBar;
Eugen Podsypalnikov 11-Dec-13 9:57am    
1. Is there "#pragma once" at the top of TextControl.h as well ? :)
2. Why is there '#include "StdAfx.h"' in a header ?
DFaeuster 11-Dec-13 10:15am    
1. There is no "#pragma once" but the normal include guard
2. In "stdafx.h" are the includes for CWnd for example.
Here is the complete content

#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxole.h> // MFC OLE classes
#include <afxodlgs.h> // MFC OLE dialog classes
#include <afxadv.h>
#include <afxcmn.h> // MFC new controls
Eugen Podsypalnikov 11-Dec-13 10:18am    
Try to include "stdafx.h" in sources (.cpp) only, like the CDTXBBAR.cpp case :)
The stdafx.h is unique for every project.

1 solution

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.
 
Share this answer
 
Comments
DFaeuster 12-Dec-13 4:31am    
Ok, it's working now.
After considering your comments, espacially with the re-definition of the class, I searched for the "CDTXBBAR.h" file on my complete hard drive and found the header file twice in different projects of my solution.
One was completely empty and the other one was the correct one.
So, when I compiled the "TextControl"-project itself it took the correct header. But during the compilation of the other project, that makes use of "TextControl" the empty file was taken.

Due to the order of the additional include directories the empty file was in front of the correct one. So after deletion of the empty file all went fine.

Now one of you might ask where the empty file comes from. I accidentially generated the "CDTXBBAR.h" file in the wrong project. Afterwards I deleted it in VS with "Remove" but not with "Delete". So the file was removed from the solution but still on the hard drive. Violá
H.Brydon 12-Dec-13 9:20am    
I don't know if it was you that downvoted the solution (3 out of 5) but since the second bullet point in the list seems to have identified the problem exactly, a +5 would be a good thing to do. :-)

Thanks for your comments.

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