DispHelper

Introduction

DispHelper is a COM helper library that can be used in C++ or even plain C. No MFC or ATL is required. It allows you to call COM objects with an easy printf style syntax.

It is compatible with most Windows compilers including Dev-C++, Visual C++ and LCC-WIN32. Including DispHelper in your project couldn't be simpler as it is available in a compacted single file version.

Included with DispHelper are over 20 samples that demonstrate using COM objects including ADO, CDO, Outlook, Eudora, Excel, Word, Internet Explorer, MSHTML, PocketSoap, Word Perfect, MS Agent, SAPI, MSXML, WIA, dexplorer and WMI.

DispHelper is free open source software provided under the BSD license.

Links

View DispHelper readme (Includes list of samples, documentation, small tutorial and further information).
DispHelper project home at Sourceforge.
Download DispHelper.
Browse DispHelper source and samples online.

Samples

/* **************************************************************************
 * RSSRead:
 *   Demonstrates a simple RSS reader using MSXML in C++.
 *
 ============================================================================ */
int main(void)
{
	CDhInitialize init;
	CDispPtr xmlDoc;
	const char * RSS_URL = "http://news.bbc.co.uk/rss/newsonline_world_edition/science/nature/rss091.xml";
	struct RSS {
		CDhStringA szTitle, szLink, szDescription;
	};

	try
	{
		/* Load the rss document from the URL */
		dhCheck( dhCreateObject(L"MSXML.DOMDocument", NULL, &xmlDoc) );
		dhCheck( dhPutValue(xmlDoc, L".Async = %b", FALSE) );
		dhCheck( dhCallMethod(xmlDoc, L".Load(%s)", szURL) );

		FOR_EACH1(xmlNode, xmlDoc, L".documentElement.getElementsByTagName(%S)", L"item")
		{
			RSS RSSItem = { 0 };

			dhGetValue(L"%s", &RSSItem.szTitle,       xmlNode, L".selectSingleNode(%S).text", L"title");
			dhGetValue(L"%s", &RSSItem.szLink,        xmlNode, L".selectSingleNode(%S).text", L"link");
			dhGetValue(L"%s", &RSSItem.szDescription, xmlNode, L".selectSingleNode(%S).text", L"description");

			cout << "Title: " << RSSItem.szTitle << endl <<
			        "Link: "  << RSSItem.szLink  << endl <<
			        "Description: " << setprecision(140) << RSSItem.szDescription << endl << endl;

		} NEXT_THROW(xmlNode);
	}
	catch (string errstr)
	{
		cerr << "Fatal error details:" << endl << errstr << endl;
	}
}


/* **************************************************************************
 * EmailOutlook:
 *   Demonstrates sending an email using Outlook in plain C.
 *
 ============================================================================ */
void EmailOutlook(LPCTSTR szTo, LPCTSTR szSubject, LPCTSTR szBody)
{
	DISPATCH_OBJ(olApp);
	DISPATCH_OBJ(olMsg);

	/* Create Outlook object and create a new mail item */
	dhCreateObject(L"Outlook.Application", NULL, &olApp);
	dhGetValue(L"%o", &olMsg, olApp, L".CreateItem(%d)", 0);

	dhPutValue(olMsg, L".Subject = %T", szSubject);
	dhPutValue(olMsg, L".To = %T",      szTo);
	dhPutValue(olMsg, L".Body = %T",    szBody);

	/* To add an attachment:
	 * dhCallMethod(olMsg, L".Attachments.Add(%s)", "FilePath.ext");
	 */

	/* Display and attempt to send email */
	dhCallMethod(olMsg, L".Display");
	dhCallMethod(olMsg, L".Send");
	
	SAFE_RELEASE(olMsg);
	SAFE_RELEASE(olApp);
}

Further Information

The DispHelper Readme provides further information including a complete list of samples and details on how to provide feedback.

Go to SourceForge.net - The open source development site