Solved

Vc++ 6.0

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

770 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