Click to See Complete Forum and Search --> : creating a com object using ATL Project


avi123
December 17th, 2003, 03:01 AM
Hello,

I'm trying to create a COM Object using ATL Project wizard.

I choose the the Attributed,DLL,Support COM+ 1.0 & support componenet register.

after that I have created a new class using add class->ATL COM+ 1.0 component(with the default setting)
and new class and a new interface were created
I saw my interface let's say IMyInterface inherits from IUnknown & IDispatch,

1. My First question is do I need to implement thier functions in my interface, I mean do I need to implement QueryInterface, AddRef,etc...?

2. I have added a new function to my IMyInterface interface
How do I call it from My client?
Do I have to load the dll?

3. except my new functions in IMyInterface, do I have to implement something else inorder to make it work?

I mean after using just the ATL wizard witout adding a class is my project already a com object doing nothing?
if not after adding my class and my interface, is it now COM object?
if it is, is it ready to be used?

I really need help here I'm really short in time

thank you all

Avi

darwen
December 18th, 2003, 10:53 AM
(1) No you don't need to implement QueryInterface, AddRef and Release as they should already be implemented by the base classes for your object.

(2) You need to call CoCreateInstance with your class CLSID, the IID of your interface (__uuidof(IMyInterface)) specifying CLSCTX_INPROC_SERVER.

(3) Your methods have to be reflected in your interface definition. I'm not too familiar with attributed interfaces, but a .h should be being generated in the project folder with the same name as your dll when you do a build so you can have a look at that and see if your methods are there.

An easier way of implementing methods is to go to class view, right click on your class and do 'add/method'. Then follow the instructions. This'll make sure you get it right every time.

Now, on server side you can put use #import to import your dll (don't load library - that's the point of COM). Have a look at the help files on #import in VC++.NET - they are very comprehensive and informative about what goes on.

Alternatively you can #include the .h which was created with the same name as your dll - that is what it's there for.

__uuidof(IMyInterface) will now work.

Darwen.

vicodin451
December 18th, 2003, 11:40 AM
Originally posted by darwen
(3)I'm not too familiar with attributed interfaces, but a .h should be being generated in the project folder with the same name as your dll when you do a build
The attributed IDL from the project is collected and dumped into a "combined" _ProjectName.IDL file. When MIDL compiles this, _ProjectName.h and _ProjectName_i.c files are generated.

avi123
January 29th, 2004, 09:19 AM
thank you both

I manged to use the COM dll with a VB client

now I have another COM dll object, for a C++ client
I created the dll, but I'm having problems using it in my C++ client

I tried to put this statment in my C++ client code (I used #import)

//////////////////////

IMyInterface iYs;
//IMyInterface is as you probably guessed is the interface,

////////////////////

but when I try to compile I got the following error:

d:\Proj\ComDllClient\Client.cpp(9): error C2259: 'IMyInterface' : cannot instantiate abstract class
due to following members:
'HRESULT IUnknown::QueryInterface(const IID &,void ** )' : pure virtual function was not defined

///////////////////////////////

1. So I guess I do have to implement them (QueryInterface etc) by myself?
2. Does it sound reasonable that I need to implemet those funtions for my C++ client but not for my VB client?

3.Can anyone pls give me a sample code?

thank you all
Avi