Javascript calls functions in ActiveX Controls
The key to this interaction is to add external methods to the interface class. The procedure is as follows:
1. Create an MFC ActiveX project in. net
2. in the class view, you can see a "project name + lib" item at the bottom. The icon is different from the class icon above. expand it and you can see three items, the following is how to add an external function under the second item ("_ d + project name ").
3. Expand the second item and you can see that there is an aboutbox (void) function below, which means some ActiveX controls already have an interface for external interaction. Right-click the interface (named "_ d + project name") and choose "Add-> Add method". Write the function name and parameter and return type (the internal name can be different from the external name ).
4. after adding the function, you can view the added function under the "C + project name + ctrl" Class in the Class View (the internal name mentioned above is displayed here ), double-click the function to write your own code.
The preceding step adds an external function of the ActiveX control. On the webpage, you can call this function in the JavaScript function. The call method is to run the "Control ID. function Name (parameter) ". The control ID here refers to the ID specified for ActiveX on the webpage, for example, <Object ID =" Control ID "classid =…> </Object>. Function name refers to the external name in step 1 above.
As shown in: three methods are defined: Login, MessageBox, and Test2.
It is worth noting that if you want to pass the javascript string to the control as a parameter, the MFC parameter should be of the BSTR type.