Click here to Skip to main content
15,891,788 members
Articles / Programming Languages / C++

Writing Win32 Apps with C++ only classes

Rate me:
Please Sign up or sign in to vote.
4.97/5 (32 votes)
1 Mar 2004CPOL21 min read 134.6K   3.5K   109  
C++ classes and wrappers to write W32 apps without MFC, ATL or other (part 1?)
//T2.cpp
#include "stdafx.h"

#include "NLib/evt.h"

using namespace GE_;

struct S
{
	int a;
	int b;

	S() { a =b = 0; }
	~S() {}
};

struct E //candidate as virtual base
{
	int _e;
	E() { _e = 0; std::cout << this << " - E ctor\n";}
	virtual ~E() { std::cout << this << " - E dtor\n";}
	virtual Hallo() { std::cout << this << " - This is E with _e = " << _e << std::endl; }
};

struct A:
	public virtual E
{
	int _a;
	A() { std::cout << this << " - A ctor\n";}
	virtual ~A() { std::cout << this << " - A dtor\n";}
	virtual Hallo() { std::cout << this << " - This is A with _e = " << _e << std::endl;  }
};


struct B:
	public virtual E
{
	int _b;
	B() { std::cout << this << " - B ctor\n";}
	virtual ~B() { std::cout << this << "- B dtor\n";}
	virtual Hallo() { std::cout << this << " - This is B with _e = " << _e << std::endl;  }
};

struct D:
	public A,
	public B
{
	D() { std::cout << this << " - D ctor\n";}
	virtual ~D() { std::cout << this << " - D dtor\n";}
	int _d;
	virtual Hallo() { std::cout << this << " - This is D with _e = " << _e << std::endl; }
};


void TestSmrtPtr()
{
	NWrp::Ptr<S>::Static PS1, PS2;
	PS1.SetOwnership(false);

	PS2.New();
	
	S* ps = PS2;

	PS2->a = 2;
	PS2->b = 3;

	PS1 = PS2;
	PS2.Detach();

	try
	{
		PS1->a = 4;
	}
	catch(exception* pe)
	{
		pe;
	}
}

void TestDynPtr()
{
	typedef NWrp::Ptr<E>::Dynamic PE;
	typedef NWrp::Ptr<D>::Dynamic PD;
	typedef NWrp::Ptr<A>::Dynamic PA;
	typedef NWrp::Ptr<B>::Dynamic PB;

	PD pD; pD.New();
	pD->_e = 1;
	pD->Hallo();
	
	PA pA;
	pA = pD;
	pA->Hallo();

	PE pE(new B);
	pE->Hallo();
	pA = pE;
	ASSERT(!pA);

	pE = new D;
	pE->Hallo();
	pA = pE;
	pA->Hallo();

	PB pB(pA);
	pB->Hallo();

	A* _pA = pD;
	_pA->Hallo();

	pB = _pA;
	pB->Hallo();

}



int _tmain()
{
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);

	TestSmrtPtr();
	TestDynPtr();


	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Architect
Italy Italy
Born and living in Milan (Italy), I'm an engineer in electronics actually working in the ICT department of an important oil/gas & energy company as responsible for planning and engineering of ICT infrastructures.
Interested in programming since the '70s, today I still define architectures for the ICT, deploying dedicated specific client application for engineering purposes, working with C++, MFC, STL, and recently also C# and D.

Comments and Discussions