Click here to Skip to main content
15,860,943 members
Articles / Desktop Programming / MFC

Resource ID Organiser Add-In for Visual C++ 5.0/6.0/.NET

Rate me:
Please Sign up or sign in to vote.
4.98/5 (71 votes)
10 Jan 2005CPOL25 min read 527.5K   12.1K   201  
An application/add-in to organise and renumber resource symbol IDs
// NGMacros.h : Macro definitions
//

#ifndef	__MACRO
#define __MACRO

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000


#ifndef __AFXWIN_H__
	#error include 'stdafx.h' before including this file for PCH
#endif


/////////////////////////////////////////////////////////////////////////////
// Definitions


//	Reserved for Help Support
//	(this code is from the Help95 sample)
#define MAKEHELPID(a, b) ((DWORD)(0x80000000 | ((DWORD)(a) << 16) | ((DWORD)(b)) ))
struct CTRLID_HELPID_PAIR
{
	CTRLID_HELPID_PAIR(DWORD x, DWORD y) : dwCtrlID(x), dwHelpID(y) {};

	DWORD dwCtrlID;
	DWORD dwHelpID;
};


#if 0
//	Wrappers for non-UNICODE safe runtime library functions
//	(avoids nasty surprises for Unicode rebuilds)
#ifdef _UNICODE
	#define IsAlpha(c)	iswalpha(c)
	#define IsDigit(c)	iswdigit(c)
	#define IsSpace(c)	iswspace(c)
	#define IsPunct(c)	iswpunct(c)
	#define IsAlNum(c)	iswalnum(c)

#else
	#define IsAlpha(c)	isalpha(c)
	#define IsDigit(c)	isdigit(c)
	#define IsSpace(c)	isspace(c)
	#define IsPunct(c)	ispunct(c)
	#define IsAlNum(c)	isalnum(c)
#endif
#endif

/***********************************************************************
 *	Use to notify the user that a method or facility is not fully implemented
 *	When compiled for debug adds an error message to the output trace and
 *	throws a debug assertion.
 *	When compiled for release, this macro has no effect.
 *
 ************************************************************************/

#define NOT_IMPLEMENTED_ERROR() \
{ \
	TRACE0("**** ERROR: Not yet implemented"); \
	ASSERT(FALSE); \
}


/***********************************************************************
 *	Helper macros to implement safe pointer attachments
 *
 *	When another object obtains a pointer to your class it can then
 *	call Attach(pointer&) to register it's interest.
 *
 *	When the server object is deleted all attached pointers will be
 *	safely NULLed.
 *
 *	To use:
 *		1.	Add DECLARE_PTR_ATTACHMENT(ClassName) to the operations
 *			section of your header file
 *
 *		2.	Add IMPLEMENT_PTR_ATTACHMENT(ClassName) to your
 *			implementation file
 *
 *		3.	Add a call to NullAttachedPointers() to the class destructor
 *
 *	These macros are provided to avoid the need for a "mix-in" class
 *	implementing this capability
 *
 ************************************************************************/

#define DECLARE_PTR_ATTACHMENT(ClassName) \
protected:\
			CPtrList		m_listReferences; \
\
			void			NullAttachedPointers(void);\
public:\
			BOOL			Attach(ClassName*& rpObj); \
			BOOL			Detach(ClassName*& rpObj);


#define IMPLEMENT_PTR_ATTACHMENT(ClassName) \
\
BOOL ClassName::Attach(ClassName*& rpObj) \
{ \
	TRACE_CALL1("Attach(0x%X)\n", &rpObj); \
\
	if (NULL == &rpObj) \
		return FALSE; \
\
	if (NULL != m_listReferences.Find( (LPVOID)&rpObj )) \
	{ \
		TRACE0("Attempted to re-attach a pointer!\n"); \
		ASSERT(0); \
		return FALSE; \
	} \
	rpObj = this; \
	m_listReferences.AddHead( (LPVOID)&rpObj ); \
	return TRUE; \
} \
\
\
BOOL ClassName::Detach(ClassName*& rpObj) \
{ \
	TRACE_CALL1("Detach(0x%X)\n", &rpObj); \
\
	POSITION pos = m_listReferences.Find( (LPVOID)&rpObj ); \
	if (NULL == pos) \
	{ \
		TRACE0("Attempted to detach unattached pointer!\n"); \
		ASSERT(0); \
		return FALSE; \
	} \
	m_listReferences.RemoveAt(pos); \
	if (this == rpObj) \
		rpObj = NULL; \
\
	return TRUE; \
} \
\
void ClassName::NullAttachedPointers(void) \
{ \
	for (POSITION pos = m_listReferences.GetHeadPosition(); pos != NULL; ) \
	{ \
		ClassName** ppObject = (ClassName**)m_listReferences.GetNext(pos); \
		if (this == *ppObject) \
			*ppObject = NULL; \
	} \
}


/***********************************************************************
 *	Provide a version of the DECLARE_SERIAL() macro which can be used
 *	in classes within MFC extension DLLs
 *
 *	Use this instead of DECLARE_SERIAL() in any classes within an
 *	extension DLL
 *
 *	Refer to MSDN Knowledge Base Article Q152254
 *	"BUG: LNK2001 on Operator>> with Class from MFC Extension DLL"
 *	for full details.
 *
 ************************************************************************/

#define DECLARE_SERIAL_EXTDLL(class_name)   \
			_DECLARE_DYNCREATE(class_name)      \
			AFX_EXT_API friend CArchive& AFXAPI \
			operator>>(CArchive& ar, class_name* &pOb);



#endif // !_MACROS_H__

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
Founder Riverblade Limited
United Kingdom United Kingdom
I haven't always written software for a living. When I graduated from Surrey University in 1989, it was with an Electronic Engineering degree, but unfortunately that never really gave me the opportunity to do anything particularly interesting (with the possible exception of designing Darth Vader's Codpiece * for the UK Army in 1990).
    * Also known as the Standard Army Bootswitch. But that's another story...
Since the opportunity arose to lead a software team developing C++ software for Avionic Test Systems in 1996, I've not looked back. More recently I've been involved in the development of subsea acoustic navigation systems, digital TV broadcast systems, port security/tracking systems, and most recently software development tools with my own company, Riverblade Ltd.

One of my personal specialities is IDE plug-in development. ResOrg was my first attempt at a plug-in, but my day to day work is with Visual Lint, an interactive code analysis tool environment with works within the Visual Studio and Eclipse IDEs or on build servers.

I love lots of things, but particularly music, photography and anything connected with history or engineering. I despise ignorant, intolerant and obstructive people - and it shows...I can be a bolshy cow if you wind me up the wrong way...Laugh | :laugh:

I'm currently based 15 minutes walk from the beach in Bournemouth on the south coast of England. Since I moved here I've grown to love the place - even if it is full of grockles in Summer!

Comments and Discussions