Solved

ActiveX Events - Parsing class types

Posted on 1998-11-30
8
300 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
 

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Creating Labels and Frequency list style reports in SAS code 9 88
Generic progress indicator 6 110
fix34  challenge 9 97
Sed question 2 48
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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 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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now