Solved

Vc++ 6.0

Posted on 1998-12-22
2
196 Views
Last Modified: 2010-04-02
I have created a generic class in a ActiveX control project , which owns some properties and member fuctions that have itself special datatype(example: CPerson) and return type(example: CPerson), how can I use it in VB? Now, I can add the controller into VB, but I can't use the member fuctions and properties that I defined myself like those  member fuctions and properties which automatically inherit from MFC.
0
Comment
Question by:WangHong
2 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 200 total points
Comment Utility
You have to make sure that CPerson is derived from CObject. Then in the constructor of the class call EnableAutomation(). Finally, you need to use IDispatch* instead of CPerson* in your methods and properties. To retrieve the IDispatch* from a CPerson* you need to use

  IDispatch* dispatch = person->GetIDispatch(FALSE);

You cannot safely convert from an IDispatch* to a CPerson* unless there is a specific interface (CLSID) that you can query IDispatch* for and get a valid interface pointer. My suggestion is to either make a specific interface and add it to CPerson's interface map. Another possible solution to this problem is to use the IDispatch interface directly. That is GetIDsofNames() and Invoke().
0
 

Author Comment

by:WangHong
Comment Utility
Sir, I have try your propose in a project. However, I still can't use the class properties or methods I defined myself. For example, I defined two classes named CPoint and CPoints use MFC class wizard as follow:
  class CPoint : public CCmdTarget
  {
   public:
      ...
   public:
     X : double;
     Y : double;
     ...(methods and properties)
   };

  class CPoints : public CCmdTarget
  {
   public:
      ...
   public:
     CPoint Items(short Index);
     void Add(CPoint aPoint);
     ...(methods and properties)
   };
   
   class CMyActiveXCtl : public COleControl
   {
    ....
    };
   And I suppose that I will use these two ActiveX Automation objects in VB 6.0 as follow:
   dim pt as new Point
   dim pts as new Points
   pt.x = 100.1
   pt.y = 200.1
   pts.Add(pt)
   
   May you tell me how can I realize these? If possible, please give me the actual steps and detail source code of the example.Thanks a lot.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now