How to call the event of MFC ActiveX on the client

Source: Internet
Author: User

Please refer to the article on codeproject:

Http://www.codeproject.com/KB/COM/ActiveXMfcState.aspx

 

 

Building the MFC Client

Our MFC client, is a plain old Appwizard generated dialog-based application with additional automation support. as usual, open VC ++ 6.0 and create a new MFC Appwizard EXE project called mfcclient. hit build to build the project, and take a break from all that hard work!

The OLE/COM Object viewer is a nifty little tool that is shipped along with Visual C ++ 6.0. it will help us generate the IDL file for the DLL component. go to tools-> OLE/COM Object viewer and open this tool. next, in OLE/COM Object viewer, click on file-> View typelib and navigate to the vbevent. DLL file that we have previusly built. ready for some magic? Click on open and open up itypelib viewer can you can view the IDL file? Whoa! Save the file through file-> Save As, as vbevents. IDL and close the tool. We have no need for it at present.

Next in our VC ++ project, add this IDL file to the project. in FileView, right click on the IDL file and choose settings. in the midl tab, set the output header file name to vbevents. h and the uuid filename to vbevents_ I .c. also deselect the mktyplib compatible option.

Save everything and in FileView, right-click on the vbevents. IDL file and choose compile. This will build the typelibrary and generate the necessary files.

Examine the midl generated vbevents_ I .c file. it contains all the uuid definitions that the client can use to build a sink object. in vbevents. h, notice the dual interface _ clseventsrc. the component's dispinterface _ clseventsrc is identified by diid ___ clsevent. this is the event source for out custom event.

The next step is to add an sink object to connect to the source event. fortunately, for us, MFC makes the task of building an event sink as easy as 1-2-3 (and well, 4-5-6) with a couple of MFC macros, you can delegate much of the intricacy involved behind building a sink to MFC. first, add a new cve-target derived class to the project called mfcsink. in the classwizard choose to select the automation option. this is our sink object with automation support.

Then import the server's typelib in the client with # import. If you haven't read my previous articles, read it here.

 

 

 

Also focus on Microsoft's ActiveX example: CIRC

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.