ActiveX Events - Parsing class types

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.
CheenAsked:
Who is Participating?
 
Tommy HuiEngineerCommented:
Let me know if there's another question you want to ask. Good luck!
0
 
CheenAuthor Commented:
Adjusted points to 150
0
 
CheenAuthor Commented:
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Tommy HuiEngineerCommented:
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
 
CheenAuthor Commented:
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
 
CheenAuthor Commented:
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
 
CheenAuthor Commented:
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
 
CheenAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.