Click here to Skip to main content
15,894,017 members
Articles / Desktop Programming / ATL

Increment File and Product Version Number - Multiple IDE

Rate me:
Please Sign up or sign in to vote.
4.58/5 (32 votes)
21 Oct 2008CPOL12 min read 293.5K   1.2K   134  
An add-in to automatically increment the FileVersion and ProductVersion fields in your application's resource file. Works in VC6 and VS2005, and probably all versions in between.
/**
 * \file IncVersion.cpp
 *
 * \brief DLL Exports for IncVersion.dll
 *
 * $Id: IncVersion.cpp, v1.1.1.1 2006/09/24 23:12:30 mgh Exp $
 *
 *
 * Copyright (C) 2006 Michael G. Herstine <sp1ff@pobox.com>
 *
 * Permission to use, copy, or modify this source code is hereby granted
 * free of charge, provided that this copyright notice appear on all
 * copies and on all source code derived from this code.  No
 * representation is made regarding the suitability of this software for
 * any purpose.  It is provided "as is" without express or implied
 * warranty.
 *
 *
 */
 
////////////////////////////////////////////////////////////////////////////
// Modified by Jordan Walters, 01.03.2008 for multi-IDE version increment //
////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"             // Pre-compiled header
#include "resource.h"           // Resource definitions
#include "AddIn.h"              // For class CAddIn
#include "IncVersion.h"			// MIDL-generated COM bindings

#include <initguid.h>           // Toggle the 'DEFINE_GUID' macro to
								// definition, rather than just
								// declaration...


// {C0002F81-AE2E-11CF-AD70-00A0C9304965}
DEFINE_GUID(IID_IDSAddIn,
			0xc0002f81, 0xae2e, 0x11cf, 0xad, 0x7, 0x0, 0xa0, 0xc9, 0x3, 0x49, 0x65);

// {8EA3F900-4A9F-11cf-8E4E-00AA004254C4}
DEFINE_GUID(IID_IApplicationEvents,
			0x8ea3f900, 0x4a9f, 0x11cf, 0x8e, 0x4e, 0x0, 0xaa, 0x0, 0x42, 0x54, 0xc4);

CIncVersionModule _AtlModule;

CTraceCategory atlTraceIncVersion("IncVersion", 1);

// DLL Entry Point
extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance,
							   DWORD dwReason,
							   LPVOID lpReserved)
{
	if (DLL_PROCESS_ATTACH == dwReason)
	{
		hInstance;
#ifdef _DEBUG
		CTrace::s_trace.SetLevel(INCVERSION_DEBUG_LOG_LEVEL);
		ATLTRACE2(atlTraceCOM, 3, "IncVersion.dll loading (0x%08x).\n", hInstance);
#endif // _DEBUG
	}
	else if (DLL_PROCESS_DETACH == dwReason)
	{
		ATLTRACE2(atlTraceCOM, 3, "IncVersion.dll un-loading.\n");

	}

	return _AtlModule.DllMain(dwReason, lpReserved);
}



// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
	ATLTRACE2(atlTraceCOM, 3, "IncVersion.dll unloading\n");
	return _AtlModule.DllCanUnloadNow();
}


// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
	return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
}


/**
 * \brief Adds entries to the system registry
 *
 *
 * \return S_OK on success, a stock error code otherwise
 *
 *
 * This method will register our COM component (CoAddIn), as well as
 * handling self-registration for our target hosts.
 *
 *
 */

STDAPI DllRegisterServer()
{
	HRESULT hr = S_OK;

	hr = _AtlModule.DllRegisterServer();
	if (FAILED(hr)) return hr;

	CRegKey hKey;
	LONG lStatus = hKey.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft")
		_T("\\DevStudio\\6.0\\AddIns"));
	if (ERROR_SUCCESS == lStatus)
	{
		ATLTRACE2(atlTraceRegistrar, 3, "This server will be registered as"
			" a DevStudio 6 AddIn.");
		hr = _AtlModule.UpdateRegistryFromResourceS(IDR_DEVSTUDIO, TRUE);
		if (FAILED(hr)) return hr;
	}

	lStatus = hKey.Open(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Vi")
		_T("sualStudio\\7.1\\AddIns"));
	if (ERROR_SUCCESS == lStatus)
	{
		ATLTRACE2(atlTraceRegistrar, 3, "This server will be registered as"
			" a Visual Studio 2003 AddIn.");
		hr = _AtlModule.UpdateRegistryFromResourceS(IDR_VS2003, TRUE);
		if (FAILED(hr)) return hr;
	}

	lStatus = hKey.Open(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Vi")
		_T("sualStudio\\8.0\\AddIns"));
	if (ERROR_SUCCESS == lStatus)
	{
		ATLTRACE2(atlTraceRegistrar, 3, "This server will be registered as"
			" a Visual Studio 2005 AddIn.");
		hr = _AtlModule.UpdateRegistryFromResourceS(IDR_VS2005, TRUE);
		if (FAILED(hr)) return hr;
	}

	// Later: Add other applications here...

	return hr;
}


// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
	HRESULT hr = S_OK;

	_AtlModule.DllUnregisterServer();

	_AtlModule.UpdateRegistryFromResourceS(IDR_DEVSTUDIO, FALSE);
	_AtlModule.UpdateRegistryFromResourceS(IDR_VS2003, FALSE);
	_AtlModule.UpdateRegistryFromResourceS(IDR_VS2005, FALSE);

	// Later: Add other applications here...

	CRegKey hKey;
	LONG lStatus = hKey.Open(HKEY_CURRENT_USER, SOFTWARE);
	if (ERROR_SUCCESS == lStatus)
	{
		lStatus = hKey.Open(hKey, KITTYLION);
		if (ERROR_SUCCESS == lStatus)
		{
			hKey.RecurseDeleteKey(INCVERSION);
		} 
	}

	return hr;
}


// Local Variables:
// fill-column: 72
// indent-tabs-mode: nil
// show-trailing-whitespace: t
// End:

// IncVersion.cpp ends here.

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
Software Developer (Senior)
United Kingdom United Kingdom
Ok, it's about time I updated this profile. I still live near 'Beastly' Eastleigh in Hampshire, England. However I have recently been granted a permamant migration visa to Australia - so if you're a potential employer from down under and like the look of me, please get in touch.
Still married - just, still with just a son and daughter. But they are now 8 and 7 resp and when together they have the energy of a nuclear bomb.
I worked at Teleca UK for over 8.5 years (but have now moved to TikitTFB) and have done loads of different things. Heavily involved with MFC, SQL, C#, The latest is ASP.NET with C# and Javascript. Moving away from Trolltech Qt3 and 4.
Jordan.

Comments and Discussions