?
Solved

Adding automation functions to CCmdTarget derived class

Posted on 2005-04-06
9
Medium Priority
?
632 Views
Last Modified: 2013-11-20

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
Comment
Question by:fxnut
  • 5
  • 4
9 Comments
 
LVL 6

Expert Comment

by:nabehs
ID: 13716864
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
 
LVL 1

Author Comment

by:fxnut
ID: 13725203
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
 
LVL 6

Expert Comment

by:nabehs
ID: 13725236
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:fxnut
ID: 13725410
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
 
LVL 6

Expert Comment

by:nabehs
ID: 13725430
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
 
LVL 1

Author Comment

by:fxnut
ID: 13726642
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
 
LVL 6

Accepted Solution

by:
nabehs earned 1400 total points
ID: 13726674
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
 
LVL 1

Author Comment

by:fxnut
ID: 13726877
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
 
LVL 6

Expert Comment

by:nabehs
ID: 13726891
glad u found the solution and thanks for the points
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question