Solved

Vc++ 6.0

Posted on 1998-12-22
2
233 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
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

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

Suggested Solutions

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 viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

828 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