Click here to Skip to main content
15,895,011 members
Articles / Desktop Programming / ATL

CWorkerThread and IWorkerThreadClient – Looking Further

Rate me:
Please Sign up or sign in to vote.
4.67/5 (8 votes)
28 Jul 2006Ms-PL5 min read 41.5K   518   37  
A tutorial on how to use the ATL7 thread class CWorkerThread and its associated helper classes CRTThreadTraits, IWorkerThreadClient etc. It also presents a generic logging component which can be used in CPU intensive applications.
// Config.h : Declaration of the CConfig

#pragma once
#include "resource.h"       // main symbols

#include "LogMan.h"


#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif



// CConfig

class ATL_NO_VTABLE CConfig :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CConfig, &CLSID_Config>,
	public ISupportErrorInfo,
	public IDispatchImpl<IConfig, &IID_IConfig, &LIBID_LogManLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
	CConfig()
	{
	}

DECLARE_REGISTRY_RESOURCEID(IDR_CONFIG)


BEGIN_COM_MAP(CConfig)
	COM_INTERFACE_ENTRY(IConfig)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()

// ISupportsErrorInfo
	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);


	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
	}

public:

public:
	STDMETHOD(get_AppName)(BSTR* pVal);
public:
	STDMETHOD(put_AppName)(BSTR newVal);
public:
	STDMETHOD(get_DbName)(BSTR* pVal);
public:
	STDMETHOD(put_DbName)(BSTR newVal);
public:
	STDMETHOD(get_DbServer)(BSTR* pVal);
public:
	STDMETHOD(put_DbServer)(BSTR newVal);
public:
	STDMETHOD(get_DbConnectString)(BSTR* pVal);
public:
	STDMETHOD(put_DbConnectString)(BSTR newVal);
public:
	STDMETHOD(get_LogDir)(BSTR* pVal);
public:
	STDMETHOD(put_LogDir)(BSTR newVal);

	private:

	_bstr_t m_bstrAppName;
	_bstr_t m_bstrLogDir;
	_bstr_t m_bstrDbServer;
	_bstr_t m_bstrDatabaseName;
	_bstr_t m_bstrDbConnectString;


};

OBJECT_ENTRY_AUTO(__uuidof(Config), CConfig)

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 Microsoft Public License (Ms-PL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions