• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 649
  • Last Modified:

Adding automation functions to CCmdTarget derived class


Hi,

I'm trying to add automation functions to a class that I've created derived from CCmdTarget. This involves adding entries into the dispatch map of the derived class. In VC++6 this could be done automatically using the class wizard's automation tab. But does anyone know how to do it in VS.NET ? There's a knowledge base entry that explains how class wizard has been integrated into the dev enviroment, but it doesn't say what happened to this particular feature (automation is mentioned for proper COM interfaces, but that doesn't help me here since I'm not dealing with a COM interface, I'm dealing with a class derived from CCmdTarget).

I came across this problem because I've been following a tutorial (link below), and it's step 5 that is causing me the problem, since I can't find a way to automatically add the functions to the dispatch map.

http://support.microsoft.com/default.aspx?scid=kb;en-us;221992

Is there a way to automatically add the Dispatch map entries?

Thanks in advance

Regards

Andy
0
fxnut
Asked:
fxnut
  • 5
  • 4
1 Solution
 
nabehsCommented:
Go to class view
Right click and select Add Class
Select MFC class
Make sure Automation radio button is checked
Enter the class name and select CCmdTarget as the base
Click OK

The class is generated

Go the Class View
expand the newly created class
you will find IMyClass interface
Right click and select Add - either method or property

0
 
fxnutAuthor Commented:
After I create the class using the method you described (which was how I was doing it), there is no interface class within the newly created class... that's the problem! The only classes in there are CCmdTarget and CObject (which CCmdTarget is derived from).

Nabehs, are you using Visual Studio .NET? If it's of any use, my About Box for MSDev shows "Microsoft Development Environment 2003 Version 7.1.3088"
0
 
nabehsCommented:
Yes, I am using the same version of Visual Studio.net

In the class view u will find CmdTarget node. expand and u will find IMyClass interface. Right click and select Add - Method or Property

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
fxnutAuthor Commented:
Thanks for your fast response nabehs.

Well, that's very strange then! I've completely expanded the tree under the class and there's definitely no interface there.

To be honest, I don't know why there should be. There's no actual interface declaration anywhere in the code that I can see, unless the DECLARE_INTERFACE_MAP() creates one that I don't know about.

I'm kinda new to this stuff, so it's perfectly possible that I haven't set something up properly, but I can definitely say that there's no interface class under the CCmdTarget in my class view.

Any ideas?!!!
0
 
nabehsCommented:
That's strange.

Assume that u created a project named MyProject. You will find a node named MyProject. Expand and u will find IMyClass interface. Add the properties and methods from there.
0
 
fxnutAuthor Commented:
Okay, I think I know what's going on here.

If I create a project WITH automation, I get an interface present in the class view, to which I am able to add functions and have them appear automatically in the dispatch map as required. (which I already knew I would be able to do).

BUT... if I create a normal (non automated) MFC project, and then add a class to the project that is derived from CCmdTarget and supports automation, I don't get any interface shown in the class view. Hence I'm not able to automatically add functions into the dispatch map. This is the problem I originally stated. I can't automatically add functions into the dispatch map for a class that I manually add to the project.

Is this in agreement to what you're finding or not?
0
 
nabehsCommented:
i think that's true. My test was with a project that supports automation and it seemed to work correctly, but u r probably right, this may be the problem
0
 
fxnutAuthor Commented:
Okay, I just created a project WITH automation, added a class, and bingo! The interface appears in the "Interfaces" section of class view.

So, the question I guess, is why a "non-automation" project doesn't show the interfaces for new classes with automation added to the project. Is there some setting somewhere? Is there some hint in the code somewhere?


Doh! I've just realised the answer. When you create a project with automation, it adds an IDL file. When you add the automated class, it also adds an entry into the IDL file which the Class View parses for it's display. When you have a non-automation project, there's no IDL file there for the Class View to show the interface.

It's a bit of a pain to have to have the IDL file there for this sort of support. Especially since there are often going to be times when you don't want to expose particular interfaces to external automation. But I guess it's not much of an issue since adding the dispatch map entries manually isn't exactly difficult.

Thanks nabehs for your help on this.
0
 
nabehsCommented:
glad u found the solution and thanks for the points
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now