That's where it gets nasty....usually the old way to share info with scripts is by the return value from main......not very decent info!!
Originally posted by PsychoBrat
but how could I use this in my app... and share certain variables/functions in my app for the user to call in his/her scripts?
These scripts as I said can use COM.....so if you want to share data between scripts, you should look at using a COM object to interface between your app and the script...
I do very little COM, but when I do I use ATL (comes with VC++6 and is like an MFC for COM). You use this tool to create a dll and add classes to it that your script can communicate with / pass data / recieve data...etc. Also, its a bit more difficult to get COM to work with scripts (as it uses a special interface called a dispatch interface) but ATL does all the work for you
Its a lot of work to understand and needs some reading on your part.....but to give you a taste, here's a basic COM object I wrote this morning to give the same functionality as my above script (I have attached the VC++ project files. Open the PoorDate.dsw file to open VC++ and click build. The dll produced houses the COM object).
When the dll is build, go to the debug dir (where you will find the actual dll) and save the following as Reg.bat
Now double click the file and windows will register your dll to be used as a com object on the system.
Now create the following script as Test.js (like my previous one - but more personal!).
Now run it and it should run as my first script, but using my ATL created COM object !
var objDate = WScript.CreateObject("PoorDate.FordyDate.1");
var objStr = "Date is ";
objStr += objDate.GetDay();
objStr += "/";
objStr += objDate.GetMonth();
objStr += "/";
objStr += objDate.GetYear();
objStr = "";
objDate = "";
WScript.Echo("Error running script!!");
When your finished, change the bat file to
and run it. This clears the registration of the dll and keeps things tidy
regsvr32 /u poordate.dll