Click here to Skip to main content
15,883,705 members
Articles / Desktop Programming / ATL

Migrating ATL service applications to Visual C++.NET

Rate me:
Please Sign up or sign in to vote.
5.00/5 (12 votes)
30 Jul 200211 min read 247.4K   1.6K   53  
Guidelines to migrate ATL-based Windows service application to Visual C++.NET
// MyService3.cpp : Implementation of WinMain

#include "stdafx.h"
#include "resource.h"

//////////////////////////////////////////////////////////////////////////////////////////////

// The module attribute causes WinMain to be automatically implemented for you

// The module attribute causes WinMain to be automatically implemented for you
[module(SERVICE, uuid="{3D87B677-0D7E-40ba-B0D4-D5D7C3B28BA6}",
		name="MyService3",
		helpstring="MyService3 1.0 Type Library",
		resource_name="IDS_SERVICENAME")]
class CServiceModule
{
public:
	HRESULT PreMessageLoop(int nShowCmd);
	HRESULT PostMessageLoop();
};

//////////////////////////////////////////////////////////////////////////////////////////////
// Service startup and registration

HRESULT CServiceModule::PreMessageLoop(int nShowCmd)
{
	HRESULT hr = __super::PreMessageLoop(nShowCmd);

#if _ATL_VER == 0x0700
	if (SUCCEEDED(hr) && !m_bDelayShutdown)
		hr = CoResumeClassObjects();
#endif

	if (SUCCEEDED(hr))
	{
		// Add any custom code to initialize your service
	}

	return hr;
}

HRESULT CServiceModule::PostMessageLoop()
{
	// Add any custom code to free your service resources

	return __super::PostMessageLoop();
}

/////////////////////////////////////////////////////////////////////////////

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect Miles AS
Norway Norway
Vagif Abilov is a Russian/Norwegian software developer and architect working for Miles. He has more than twenty years of programming experience that includes various programming languages, currently using mostly C# and F#.

Vagif writes articles and speaks at user group sessions and conferences. He is a contributor and maintainer of several open source projects, including Simple.Data OData adapter, Simple.OData.Client and MongOData.

Comments and Discussions