The client calls com to implement interface calls and COM Event Notifications.

Source: Internet
Author: User

//###################################### ######### <Br/> // note the following: <br/> // (1) You must use # import "xxxx/helloworld. DLL ". In this case, the compiler will generate <br/> // helloworld. tlh, helloworld. TLI <br/> // (2) The namespace using namespace helloworldlib must be set; <br/> //################################## ############# </P> <p> // The following interface must be implemented <br/> class cocallback: public idispatch <br/>{< br/> Public: <br/> virtual hresult stdmethodcalltype gettypeinfocount (<br/>/* [out] */uint * pctinfo) <br/>{< br/> return e_notimpl; <br/>}</P> <p> virtual hresult stdmethodcalltype gettypeinfo (<br/>/* [in] */uint itinfo, <br/>/* [in] */lcid, <br/>/* [out] */itypeinfo ** pptinfo) <br/>{< br/> return e_notimpl; <br/>}</P> <p> virtual hresult stdmethodcalltype getidsofnames (<br/>/* [in] */refiid riid, <br/>/* [size_is] [in] */lpolestr * rgsznames, <br/>/* [in] */uint cnames, <br/>/* [in] */lcid, <br/>/* [size_is] [out] */dispid * rgdispid) <br/>{< br/> return e_notimpl; <br/>}</P> <p> virtual/* [local] */hresult stdmethodcalltype invoke (<br/>/* [in] */dispid dispidmember, <br/>/* [in] */refiid riid, <br/>/* [in] */lcid, <br/>/* [in] */word wflags, <br/>/* [out] [in] */dispparams * pdispparams, <br/>/* [out] */variant * pvarresult, <br/>/* [out] */variable info * p1_info, <br/>/* [out] */uint * puargerr) <br/> {<br/> MessageBox (null, "1111111", "2222222", mb_ OK ); </P> <p> return s_ OK; <br/>}</P> <p> stdmethod _ (ulong, addref )() <br/>{< br/> return e_notimpl; <br/>}</P> <p> stdmethod _ (ulong, release )() <br/>{</P> <p> return e_notimpl; <br/>}</P> <p> stdmethod (QueryInterface) (refiid riid, void ** ppvobject) <br/>{< br/> * ppvobject = This; // debugging result <br/> return s_ OK; <br/>}</P> <p> }; </P> <p> cocallback gpcallback; </P> <p> int _ tmain (INT argc, _ tchar * argv []) <br/>{< br/> coinitialize (null); </P> <p> // obtain the object of the Interface Class in the DLL <br/> ihelloatlcontrolptr lcmhelloobj; <br/> hresult HDR = lcmhelloobj. createinstance (_ uuidof (helloatlcontrol); <br/> If (xr = s_ OK) <br/>{< br/> // execute the export function <br/> lcmhelloobj-> exportfun1 (); <br/>}</P> <p> // Add the callback class of the program to the connection container (in vect) in COM ), to notify the client <br/> iconnectionpointcontainer * lpconnectionpointcontainer = NULL; <br/> lcmhelloobj. queryInterface (iid_iconnectionpointcontainer, (void **) & lpconnectionpointcontainer); <br/> If (lpconnectionpointcontainer) <br/>{< br/> iconnectionpoint * lpconnectionpoint = NULL; <br/> lpconnectionpointcontainer-> findconnectionpoint (_ uuidof (_ ihelloatlcontrolevents), & lpconnectionpoint); </P> <p> lpconnectionpointcontainer-> release (); <br/> lpconnectionpointcontainer = NULL; </P> <p> If (lpconnectionpoint) <br/>{< br/> DWORD ldwcookie = 0; <br/> // Add to the class container in COM <br/> lpconnectionpoint-> advise (& gpcallback, & ldwcookie ); <br/>}</P> <p> lcmhelloobj-> exportfun1 (); <br/> lcmhelloobj = NULL; </P> <p> couninitialize (); </P> <p> return 0; <br/>}< br/>

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.