Click here to Skip to main content
Click here to Skip to main content

Embeddable script editor for MFC applications

, 15 Jul 2003
Rate this:
Please Sign up or sign in to vote.
A library that allows you to embed scripting functionality to your C++ MFC application.

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

Share

About the Author

Alex Hazanov
Software Developer (Senior) RDV Systems
Israel Israel
No Biography provided

Comments and Discussions

 
QuestionCode License PinmemberMember 1063802210-Mar-14 23:57 
GeneralAdding a new Class in the ScripTestLib to add functions in the Script Editor Pinmemberbrestian15-Jan-07 3:50 
Hello,
 
I try to create my own Class (a kind of another SimpleObject) in the ScriptTestLib to add new functions in the Script Editor ...
 
At first, I added new functions in the actual SimpleObject Class ... no problem it works great. I did it by using the "Add Method" in the COM wrapper then I checked that everything was ok in the ScriptTest.odl. I can see my new fucntions in the ScriptEditor, cool.
 
Now I create a new Class in the ScriptTest project. I choose a MFC Class and I tick the "automation" support.
The new Class is created and I can see in ScriptTest.odl the dispatch interface for it. Then, as above, I add a fucntion with "Add Method" ... I can see now my new method listed under ScripTestLib/IMyNewClass, others are under ScriptTestLib/ISimpleObject. So far so good.
 
Then, I add in my InitDialog the famous line:
scripter.AddObject("MyNewClass",m_myNewClass.GetIDispatch(TRUE));
 
In the Script Editor, I can indeed see "MyNewClass" but not method available when I type MyNewClass. ... OMG | :OMG:
 
So I guess I do something wrong ... does anyone could help me ?
Thanks in adavnce and thanks Alex for your great job.
 
Brestian
 

GeneralRe: Adding a new Class in the ScripTestLib to add functions in the Script Editor Pinmembervccai7-Feb-07 3:02 
GeneralRe: Adding a new Class in the ScripTestLib to add functions in the Script Editor Pinmemberconfideman200010-Feb-12 21:56 
GeneralMulti-threading Pinmemberjkhax0r8-Nov-06 13:30 
GeneralCOM projects Pinmemberdaniel remedi29-Jul-06 4:06 
GeneralLNK2001 Error for CreateEngine Pinmemberrbuchana5-Jul-06 6:46 
GeneralRe: LNK2001 Error for CreateEngine Pinmemberrbuchana7-Jul-06 11:37 
GeneralRe: LNK2001 Error for CreateEngine Pinmemberrbuchana14-Jul-06 6:39 
GeneralRe: LNK2001 Error for CreateEngine Pinmemberbrestian12-Jan-07 4:51 
GeneralRe: LNK2001 Error for CreateEngine Pinmembertotobby31-Jan-07 6:38 
GeneralRe: LNK2001 Error for CreateEngine Pinmembersunbelt578-Feb-14 15:33 
GeneralRe: LNK2001 Error for CreateEngine Pinmembersunbelt578-Feb-14 15:49 
GeneralIt seems headers in demo and source do not match Pinmemberzhaozh18-Aug-05 12:53 
GeneralRe: It seems headers in demo and source do not match PinmemberAlex Hazanov19-Aug-05 12:02 
GeneralMemory leaks Pinmemberarielevt12330-Jul-05 5:58 
GeneralRe: Memory leaks Pinmemberarielevt1235-Aug-05 8:02 
GeneralCreate a new function Pinmemberarielevt12310-Jul-05 10:08 
GeneralRe: Create a new function PinmemberAlex Hazanov10-Jul-05 21:25 
QuestionAnd what about Lua ? PinmemberKochise18-Feb-05 5:10 
AnswerRe: And what about Lua ? PinmemberAlex Hazanov19-Feb-05 6:47 
GeneralBUG? Pinmembercnmusic31-Jul-04 23:41 
GeneralProblem w/ events PinmemberDe Nardis Andrea20-Jul-04 0:01 
GeneralRe: Problem w/ events PinmemberAlex Hazanov19-Feb-05 6:40 
GeneralRe: Problem w/ events PinmemberDe Nardis Andrea20-Feb-05 21:31 
GeneralRe: Problem w/ events PinmemberAlex Hazanov21-Feb-05 0:06 
GeneralDebug assertion failed in debug version! PinmemberTLFLY7-Apr-04 23:32 
QuestionBuilds on VC 7.1? Pinmembergofootn25-Feb-04 12:59 
AnswerRe: Builds on VC 7.1? Pinmembertouch_me_20207-Nov-04 21:06 
GeneralRe: Builds on VC 7.1? PinmemberAlex Hazanov7-Nov-04 21:11 
AnswerRe: Builds on VC 7.1? PinmemberKim, YongChull13-Jul-05 16:37 
AnswerRe: Builds on VC 7.1? PinmemberAdrian Savage30-Aug-06 5:39 
Questionhow can I use wscripter? Pinmemberdaveice22-Feb-04 16:36 
AnswerRe: how can I use wscripter? PinmemberAlex Hazanov23-Feb-04 20:30 
GeneralImplemation of IActiveDeubg Pinmemberdaveice11-Jan-04 15:36 
GeneralRe: Implemation of IActiveDeubg PinmemberAlex Hazanov14-Jan-04 23:16 
GeneralRe: Implemation of IActiveDeubg Pinmemberdaveice16-Jan-04 14:50 
GeneralRe: Implemation of IActiveDeubg Pinmemberdaveice16-Jan-04 15:06 
GeneralRe: Implemation of IActiveDeubg PinmemberAlex Hazanov18-Jan-04 23:17 
GeneralQuestion about AddObject() PinmemberJ.G. Hattingh24-Dec-03 0:14 
GeneralRe: Question about AddObject() PinmemberAlex Hazanov24-Dec-03 5:42 
GeneralRe: Question about AddObject() PinmemberJason Hattingh24-Dec-03 5:47 
GeneralI would value this very much: PinmemberJ.G. Hattingh23-Dec-03 9:20 
GeneralI get "Permission Denied" error PinmemberJ.G. Hattingh23-Dec-03 6:25 
GeneralRe: I get "Permission Denied" error PinmemberAlex Hazanov23-Dec-03 12:12 
GeneralRe: I get "Permission Denied" error PinmemberJ.G. Hattingh24-Dec-03 0:11 
GeneralRe: I get "Permission Denied" error (solution found) PinmemberJ.G. Hattingh24-Dec-03 0:48 
GeneralRe: I get "Permission Denied" error (solution found) PinmemberAlex Hazanov24-Dec-03 5:49 
GeneralRe: I get "Permission Denied" error (solution found) PinmemberJason Hattingh24-Dec-03 5:53 
GeneralRe: I get "Permission Denied" error (solution found) PinmemberJason Hattingh24-Dec-03 5:59 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 16 Jul 2003
Article Copyright 2003 by Alex Hazanov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid