Solved

Vc++ 6.0

Posted on 1998-12-22
2
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 200 total points
ID: 1180877
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
ID: 1180878
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

724 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