In general, you can use CoCreateInstance to invoke the COM component. But for the COM component implements IDispatch interface, there are easier ways - automatically generated interface with VC ++ COleDispatchDriver wrapper class to call the COM component.
For example: execute scripts statement in VC ++, such as VBScript statement.
The system provides a control: C: \ WINDOWS \ system32 \ msscript.ocx, which provides an interface called IScriptControl through it, we can execute the script statements.
1. VC ++ wrapper classes created automatically
MFC with VC support the establishment of a project, add a class, select the "type of MFC class library," and then select msscript.ocx file and IScriptControl added to the right column, as shown ++: can be generated after clicking the completion CScriptControl packaging .
2. using the generated class
//
initialize the
COM
library
CoInitialize(NULL);
//
create
MSScriptControl.ScriptControl
instance
//
The name (ProgId) by
VC ++
gadget directory
oleview
get.
CScriptControl js;
if (js.CreateDispatch("MSScriptControl.ScriptControl"))
{
//
set the current scripting language used
js.put_Language("JScript");
//
execute a statement
,
after the completion of the implementation of
var
ie it contains the result of the expression
VARIANT var=js.Eval("1.234+5.31");
//
release Interface
js.ReleaseDispatch();
}
//
close the
COM
library
CoUninitialize();
3. The other use of this embodiment
can be conveniently packaged as a dot code these expression evaluator.
can be conveniently packaged as a dot code these expression evaluator.
Reproduced in: https: //www.cnblogs.com/rogee/archive/2011/02/19/1958690.html