Solved

ActiveX Events - Parsing class types

Posted on 1998-11-30
8
303 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
  • 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
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.

 

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 93
windows 10 how make picture as desktop background 2 62
How to know only "File created" with EventLog 3 34
method notes when mouse over in eclipse 5 87
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 …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

810 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