Click here to Skip to main content
15,881,852 members
Articles / Programming Languages / C#

Automating Windows Applications

Rate me:
Please Sign up or sign in to vote.
4.95/5 (137 votes)
1 Feb 2003CPOL11 min read 392.1K   12.3K   309  
A Windows application that does not export any program interface, may be converted to automation server with COM object(s) injected into the application process.
// Advise.cpp

#include "stdafx.h"
#include "Advise.h"


/////////////////////////////////////////////////////////////////////////////////////////
//	CAdvise 
//
CAdvise::CAdvise(const IID& iidSinkInterface) :
	m_iidSinkInterface(iidSinkInterface), 
	m_dwCookie(0)
{	
}

CAdvise::~CAdvise()
{
	UnadviseToServer();
}

HRESULT CAdvise::AdviseToServer(IUnknown* pUnk, const IUnknown* pUnkEvents)
{
	CComPtr<IConnectionPointContainer> spCPCtr;
	HRESULT hr = pUnk->QueryInterface( IID_IConnectionPointContainer, (void**)&spCPCtr );
	if ( SUCCEEDED(hr) )
	{
		hr = spCPCtr->FindConnectionPoint( m_iidSinkInterface, &m_spCP );
		if ( SUCCEEDED(hr) )
			hr = m_spCP->Advise( (IUnknown*)pUnkEvents, &m_dwCookie );
	}

	return hr;
}

void CAdvise::UnadviseToServer()
{
	if ( m_spCP && 0 < m_dwCookie )
		m_spCP->Unadvise( m_dwCookie );
}

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)
Israel Israel


  • Nov 2010: Code Project Contests - Windows Azure Apps - Winner
  • Feb 2011: Code Project Contests - Windows Azure Apps - Grand Prize Winner



Comments and Discussions