views:

110

answers:

1

I've been reading Essential COM, it is a very good book, very instructive and simple to understand. Now I want to speed things up and implement a simple COM object, compile it into a .dll and finally use it from a client application.

I would really appreciate if anybody could show the most basic sample of how to do that?

I've been trying with this step by step but, besides founding some errors, I could not make it work. The reason for this is that I've created a simple Win32 application, I started coding the COM from scratch (as the step by step shows) and fails to compile/link (lot of errors), I must be forgetting some configuration or some includes in stdafx.h or whatever.

I'm working in Visual C++ with Microsoft Visual Studio .Net 2003

Thanks in advance!

+1  A: 

One of the most friction-free ways is to use one of the wizard-generated solutions, and in particular the "ATL Project" wizard in VS 2008 (not sure about 2003). You just select "DLL" when asked the server type you want, and you're left with a very usable COM DLL skeleton where to fill in your code.

Tip: to add a new COM interface and coclass, the easiest way is to go to Class View, right-click on the project, and select Add->Class..., then select "ATL Simple Object" and answer the wizard questions.

EDIT: to answer Toto's additional question in the comments (how to create a client to use the freshly-created COM DLL), the answer is "it depends on the language", as you have an enormous choice here. You can use VB ("add reference"), C#/VB.NET ("add reference", COM tab), VBScript (WScript.CreateObject), and of course C++ too. In a nutshell, from a C++ client you need to include the server's IDL and link to the server's LIB file.

Guido Domenici
Thanks! Now I have my COM object compiled into a DLL and registered. Now I want to implement a client for that object (in a new visual studio project).What files from the previous project do I need to include in this new project??
Toto
you need to include _i.c, _i.h/.h file.
Vinay