Solved

ActiveX Events - Parsing class types

Posted on 1998-11-30
8
305 Views
Last Modified: 2013-11-20
I am currently doing an ActiveX Control in MS VC++ 5 and am wondering if it is possible to pass a Class structure to say the container of the ActiveX Control via the event firing mechanism within the control. The Control was created using MFC.

For example, I have a class as defined below....

class MyClass
{
     public:
          long i;
          long j;
          long k;
         CString SingleString;
         CStringList MultiString;
};

MyClass TheTestClass;

After initialization of TheTestClass which is an instance of MyClass, I call an ActiveX automation method that fires the event FireReturnTheClass(TheTestClass) which takes the class as a parameter.

The question is, is this possible and if so, which parameter type (ie. VARIANT, BSTR etc.) would I need to use in the events tab dialog box in the MFC class wizard to make this work? Are there any examples on the MSDN or on the Internet where I can get some ideas for this particular example? Any information that would lead to a solution to this problem will be very much appreciated.

Thanks in advance.
0
Comment
Question by:Cheen
[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
  • 6
  • 2
8 Comments
 

Author Comment

by:Cheen
ID: 1325531
Adjusted points to 150
0
 

Author Comment

by:Cheen
ID: 1325532
What the heck, make it 300 points! I really hope that there is someone out there who has a solution to such a problem :)
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1325533
It is possible.

But instead of making the type a LONG or such, you need to return an IDispatch*. You need to then create a class derived from CCmdTarget, calling it CMyClass. When you create an instance of CMyClass, it should also have a pointer to the MyClass object. The CMyClass is basically a wrapper for MyClass structure. You need to provide member functions or properties on the CMyClass class to allow you to work with the structure.

Then to return the CMyClass object as an IDispatch, you use CMyClass::GetIDispatch(FALSE) to return the object.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Cheen
ID: 1325534
I am a bit unclear here. Do you mean that the class that I created needs to be referenced by another class derived from CCmdTarget (call it CToReturn) and this CToReturn class will be used within the FireReturnTheClass event parameter field?

Besides that, what would the "Type" be? LPDISPATCH? Not sure here, but I am using the ClassWizard to do the stuff for the events return and I am not sure which Type I would need to use in the ActiveX Events Tab box.

Would it make it a bit clearer if I sent you the test control I'm working on?
0
 

Author Comment

by:Cheen
ID: 1325535
I am looking for _events_ to return to the container. Looking at the help files within VC5, it says that this is for automation which is communication via client to the control and not the other way around. I may be wrong about this, but if it is possible, I'd like an example of how this is done. That is, how an activeX control can return a class in its event parameter field. These are going out of the control to the container. I want the container to get information of the class when the control has processed it.
0
 

Author Comment

by:Cheen
ID: 1325536
thui,

Sorry I rejected your answer initially. I've modified my code a bit and changed some bits as well. Now, class MyClass inherits CCmdTarget functionality. I've also added EnableAutomation() into the contructor of MyClass. Then, in the FireReturnTheClass event, I've defined the parameter type as a LPDISPATCH type taking an instance of MyClass and using the GetIDispatch(FALSE) member function to cause the class to be returned to the container. So the FireReturnTheClass event looks like this... FireReturnTheClass(TheTestClass.GetIDispatch(FALSE)); where TheTestClass is an instance of MyClass.

Unfortunately, I'm not too sure if the class did get parsed. Using the ActiveX Test Container that ships with VC5, it looks like the event fires but the problem is it comes up with a <Unknown> tag for MyClass. ie. ReturnTheClass(MyClass=<Unknown>). I will be investigating this further by implementing my own container and see if it really parses the class over by stepping thru the program. If it works or not, I'll let you know. Just lock the question again and I'll give you the points (unless there is an easier way). Thanks for your help :)
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 300 total points
ID: 1325537
Let me know if there's another question you want to ask. Good luck!
0
 

Author Comment

by:Cheen
ID: 1325538
Thanks for your help Thui. Really appreciate it. I will be posting up some more questions, maybe somewhere along what I said because there is some problems there that needs resolving. But thanks for at least you gave me a head start :) TQ!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 201
Error on moodle after upgrade 3 149
Unix / Linux grid computing 5 169
Smart Camera scanning and reading information 3 122
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.

730 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