One-step interaction between ActiveX Components developed by ATL and JavaScript (1)

Source: Internet
Author: User

1. Open vs2008 and click "new project…" on the start page ...", Select the "ATL Project" project under the "ATL" category. The project name is "atltest ". In the Project Wizard that appears later, use the default configuration. <? XML: namespace prefix = o ns = "urn: Schemas-Microsoft-com: Office: office"/>

<? XML: namespace prefix = v ns = "urn: Schemas-Microsoft-com: VML"/>


 

 

 

2. Add controls

Right-click the project in solution manager, select "add" and "class", and select the ATL control type under the ATL category in the add class dialog box. Click "add". The Add ATL control wizard is displayed. Enter the control name "calc". Do not use the same name as the project name. In the optionas window that appears, set interface to "dual", and support to "connection point,

 

 

Note: If you use vs2010 to display the interface for selecting the control to implement, you can add the IObjectSafety interface in addition to the implementation added by default by, this interface can be used to prevent insecure scripts that run in IE when the control is used. (Vs2008 needs to add its own interface ).

3. Add and implement controls

In the Class View window, right-click the ic1c interface and select "add" and "add method ...", Assume that we implement an addition operation, name the method "add", and then add the parameter:

 


You must note the processing of the returned values. Set the parameter type to double * and select the "retval" check box.

After the Wizard is complete, vs automatically adds an empty implementation of this method to calc. cpp, and adds the modified method to it.CodeIs:

Stdmethodimp ccalb: add (double A, double B, double * result)

{

* Result = A + B;

Return s_ OK;

}

Test this method:

Modify the HTM automatically generated by vs for testing to test the addition method. The modified HTM code is as follows:

<HTML>

<Head>

<Title> ATL 8.0 test page for object calc </title>

</Head>

<Body>

<Object ID = "calc" classid = "CLSID: EEE5C4D7-B87B-4F0A-86BC-A517A9F94311"> </Object>

<Input type = "button" value = "add" onclick = "add ();"/>

<Input type = "button" value = "callwebjs" onclick = "test ();"/>

<SCRIPT type = "text/JavaScript">

Function add (){

VaR calc = Document. getelementbyid ('calc ');

VaR result = Calc. Add (2, 3 );

Alert (result );

}

Function Test (){

VaR calc = Document. getelementbyid ('calc ');

VaR result = Calc. callwebjs (printmsg ('you are welcome !!! '));

}

Function printmsg (MSG ){

Alert (MSG );

}

</SCRIPT>

</Body>

</Html>

Click the Add button and the running result is as follows:

 


So far, we have implemented a single call from web to ActiveX. The next article will introduce callback JS from ActiveX

 

 

From: http://hi.baidu.com/hwygy_001/item/b73aa4f27fdd6edb6225d23b

Related Article

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.