Click here to Skip to main content
15,881,588 members
Articles / Desktop Programming / MFC
Article

Embeddable script editor for MFC applications

Rate me:
Please Sign up or sign in to vote.
4.90/5 (60 votes)
15 Jul 20032 min read 335.1K   6.4K   130   124
A library that allows you to embed scripting functionality to your C++ MFC application.

Image 1

Objects Events Listing

Sample screenshot

Pop-Up Object properties and methods list

Sample screenshot

IntelliSense - like function parameters tooltips

Introduction

I've been searching the net for a suitable and affordable solution that will allow me to embed scripting functionality in my C++ application. What I found was either not sufficient or cost a lot of money.

So I've decided to make one of my own. After about a month of work and testing I've come up with this embeddable scripter.

I made it a separate DLL , which is really easy to use.

Usage

  1. Download the source code, and compile it. Make sure to compile the correct version (Debug\Release) or both.
  2. Include ScriptEditor.h in your project and add the library ScriptEditor.lib to your additional libraries. Make sure to reference the correct version! Debug version for debugging and release version for release!
  3. Copy the DLL to the same folder as your executable.
  4. In your code create an instance of CScripter and initialize it.
  5. Add your objects to the script and optionally the script text.

Example

In the header of your main application window add:

#include "..\ScriptEditor\Scripter.h"

Add member variable:

CScripter scripter;

Then when initializing add:

scripter.CreateEngine("VBScript");

After that add your objects to the script:

scripter.AddObject("MPlayer",(IDispatch *)m_mediaPlayer.GetControlUnknown());
scripter.AddObject("PlayButton", 
      (IDispatch *)m_commandButton.GetControlUnknown());
scripter.AddObject("TabStrip",(IDispatch *)m_tabStrip.GetControlUnknown());
scripter.AddObject("SimpleObject",m_simpleObject.GetIDispatch(TRUE));

And optionally set the script text:

scripter.scriptText = "MsgBox \"Test message\"";

After that the script is ready to run, you now may do one of the following:

// Run the script
scripter.StartScript();

// Stop the script execution

scripter.StopScript();

// Open the script editor window

scripter.LaunchEditor();

// Reset the script (All added objects are removed and engine is recreated)

scripter.Reset();

History

This is the first release so it's probably not bug free. I've done my best to track any bugs but there are always surprises. So I will post here any additions, patches and fixes that will follow.

  • 19/07/03 - The DLL source was updated to compile in VS.NET (read the messages below)

Credits

  • Gil Eizenburg for debugging and testing.
  • Smaller Animals Software, Inc. for ColorEditWnd class.
  • Daniel Madden for CTokenEx class.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) RDV Systems
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Some bugs (2) Pin
Alex Hazanov15-Sep-03 11:13
Alex Hazanov15-Sep-03 11:13 
Generalfeature request Pin
Brian van der Beek18-Aug-03 21:27
Brian van der Beek18-Aug-03 21:27 
GeneralRe: feature request Pin
Alex Hazanov20-Aug-03 4:49
Alex Hazanov20-Aug-03 4:49 
GeneralRe: feature request Pin
Brian van der Beek20-Aug-03 4:52
Brian van der Beek20-Aug-03 4:52 
GeneralRe: feature request Pin
Alex Hazanov20-Aug-03 5:02
Alex Hazanov20-Aug-03 5:02 
GeneralRe: feature request Pin
Brian van der Beek20-Aug-03 5:20
Brian van der Beek20-Aug-03 5:20 
GeneralRe: feature request Pin
Anonymous15-Sep-03 7:59
Anonymous15-Sep-03 7:59 
GeneralRe: feature request Pin
Alex Hazanov15-Sep-03 11:10
Alex Hazanov15-Sep-03 11:10 
GeneralRe: feature request Pin
Brian van der Beek22-Sep-03 22:27
Brian van der Beek22-Sep-03 22:27 
GeneralSome bugs: Pin
Brian van der Beek17-Aug-03 4:02
Brian van der Beek17-Aug-03 4:02 
GeneralRe: Some bugs: Pin
Alex Hazanov20-Aug-03 4:41
Alex Hazanov20-Aug-03 4:41 
GeneralUpdated version Pin
Alex Hazanov1-Aug-03 11:08
Alex Hazanov1-Aug-03 11:08 
GeneralRe: Updated version Pin
Brian van der Beek14-Aug-03 9:27
Brian van der Beek14-Aug-03 9:27 
GeneralRe: Updated version Pin
Jason Troitsky (was Hattingh)23-Dec-03 9:13
Jason Troitsky (was Hattingh)23-Dec-03 9:13 
QuestionIt doesn't seem to work with Vanilla MFC Automation - Should it? Pin
AbbeytekMD23-Jul-03 4:23
AbbeytekMD23-Jul-03 4:23 
AnswerRe: It doesn't seem to work with Vanilla MFC Automation - Should it? Pin
Alex Hazanov23-Jul-03 4:33
Alex Hazanov23-Jul-03 4:33 
AnswerRe: It doesn't seem to work with Vanilla MFC Automation - Should it? Pin
Alex Hazanov23-Jul-03 20:38
Alex Hazanov23-Jul-03 20:38 
GeneralFor All those who use VS.NET (VC++ 7) Pin
Alex Hazanov19-Jul-03 8:18
Alex Hazanov19-Jul-03 8:18 
GeneralCompiling in VS.net Pin
gobinath_p18-Jul-03 20:53
gobinath_p18-Jul-03 20:53 
QuestionNot suport Unicode? Pin
qinyong9918-Jul-03 20:02
qinyong9918-Jul-03 20:02 
AnswerRe: Not suport Unicode? Pin
Alex Hazanov19-Jul-03 8:23
Alex Hazanov19-Jul-03 8:23 
GeneralRe: Not suport Unicode? Pin
qinyong9919-Jul-03 16:27
qinyong9919-Jul-03 16:27 
GeneralRe: Not suport Unicode? Pin
zhutongzhjd19-Jul-03 16:31
zhutongzhjd19-Jul-03 16:31 
GeneralFIX: "Scripter.obj : error LNK2001: unresolved external symbol _IID_IActiveScriptParse32" Pin
Christian Skovdal Andersen17-Jul-03 21:33
Christian Skovdal Andersen17-Jul-03 21:33 
GeneralRe: FIX: "Scripter.obj : error LNK2001: unresolved external symbol _IID_IActiveScriptParse32" Pin
vipulparmar17-Jan-06 19:44
vipulparmar17-Jan-06 19:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.