Use the COleDispatchDriver package class of the VC ++ generation interface to call the COM component.

Source: Internet
Author: User
Generally, you can use cocreateinstance to call the COM component. However, for the COM component that implements the idispatch interface, it is easier to call the COM component by using the coledispatchdriver package class of the VC ++ automatically generated interface. Example: execute script statements in VC ++, such as VBScript statements. The system provides a control: c: \ windows \ system32 \ msscript. ocx, which provides an interface called iscriptcontrol, through which we can execute script statements. 1. Use VC ++ to automatically create a packaging class
Use VC ++ to create a project that supports MFC, add a class, select "MFC class in the Type Library", and then select msscript. ocx file, and add iscriptcontrol to the right bar, such:


 
Click Finish to generate the cscriptcontrol packaging class.2. Use the generated class
// Initialize the com library coinitialize (null); // create a msscriptcontrol. scriptcontrol instance // This name (progid) can be obtained through the tool oleview in the VC ++ directory. Cscriptcontrol JS;If(Js. createDispatch ("MSScriptControl. scriptControl ") {// sets the currently used scripting language js. put_Language ("JScript"); // execution statement. After execution, var contains the expression result.VARIANTVar = js. Eval ("1.234 + 5.31"); // release the js. ReleaseDispatch ();} // close the COM library CoUninitialize ();3. Other functions of this example

This code can be easily encapsulated into an expression calculator.

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.