Click here to Skip to main content
15,896,606 members
Articles / Desktop Programming / Win32

A Simple Yet Debuggable COM Skeleton Code

Rate me:
Please Sign up or sign in to vote.
4.91/5 (50 votes)
9 Nov 200215 min read 244K   2.5K   115  
Tutorial showing how to build COM components from scratch (DLL, EXE, automation)
In this article, you will learn how to write working COM components from scratch, and without a single macro.
// automexeserver.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include <objbase.h> // 
#include "automexeserver_i.h"
#include "automexeserverImpl.h"

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{

	// register/unregister server on demand
	//
	char szUpperCommandLine[MAX_PATH];
	strcpy (szUpperCommandLine, lpCmdLine); // copy command line and work with it.
	strupr (szUpperCommandLine);
	if (strstr (szUpperCommandLine, "UNREGSERVER"))
	{
		DllUnregisterServer();
		return 0;
	}
	else if (strstr (szUpperCommandLine, "REGSERVER"))
	{
		DllRegisterServer();
		return 0;
	}


	// initialize the COM library
	::CoInitialize(NULL);

	// register ourself as a class object against the internal COM table
	// (this has nothing to do with the registry)
	DWORD nToken = CoEXEInitialize();


	// -- the message poooommmp ----------------
	//
	// (loop ends if WM_QUIT message is received)
	//
	MSG msg;
	while (GetMessage(&msg, 0, 0, 0) > 0) 
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
		

	// unregister from the known table of class objects
	CoEXEUninitialize(nToken);

	// 
	::CoUninitialize();


	

	return 0;
}



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.


Written By
France France
Addicted to reverse engineering. At work, I am developing business intelligence software in a team of smart people (independent software vendor).

Need a fast Excel generation component? Try xlsgen.

Comments and Discussions