newObjects-logo.gif (1024 bytes) ScriptManager2 reference

SCPHOSTCLNT - C++ helper object for the ScriptManager2

Class has only one constructor without parameters - SCPHOSTCLNT(). Object created tries to create ScriptManager2 instance immediatelly and holds it until destroyed. Thus usage of the ScriptManger2 in a C++ program is simplified to using this typical C++ class as a bridge to the ScriptManager2 ActiveX.

Class is designed to provide C++ object behaviour for the ScriptManager2 - it holds internally instance of the ActiveX. Lifetime of the instance is controled by the SCPHOSTCLNT as long as the GetSelfDispatch method is not used to obtain and hold externally an interface pointer to the ActiveX. When destructed SCPHOSTCLNT closes the script thus usage of the externally holded interface pointers can be dangerous if they must point to the initialized and running script. In these cases be careful to synchronize the life-times.

One example simple cicle of the ScriptManager2 usage can be:

SCPHOSTCLNT host;
if (!host.Success()) {
   // handle the error
}
if (!host.LoadEngine("JScript")) {
  // Handle error
}
// Call Add to add items if any
// Obtain script code in the szScript buffer
host.AddCode(szScript);
if (!host.Run()) {
  // Handle error
}
host.Close();

If the code above is in a function scope it will create an instance of the ScriptManager2 load and execute the script and release the ScriptManager2 when the function returned.

See console and MFC examples to see class in action.

See also Compilation and Linking

newObjects Copyright newObjects 2001-2005