Starting JScript engine from emVC++ 3.0 on CE 3.0 
Author Message
 Starting JScript engine from emVC++ 3.0 on CE 3.0

I'm looking to fire up a JScript engine, pass it the name of a local
JSscript file for it to execute, and wait until the execution is
finished. Can anyone provide sample code of how to do this?

Thanks,
--------------------------------------------------------
Steve Rothkin
Datalinx Corp.
505 White Plains Road
Tarrytown, NY 10591
Voice: (914)333-0882 ext 105
Fax:   (914)333-0882



Tue, 26 Aug 2003 18:54:03 GMT  
 Starting JScript engine from emVC++ 3.0 on CE 3.0


Quote:
>I'm looking to fire up a JScript engine, pass it the name of a local
>JSscript file for it to execute, and wait until the execution is
>finished. Can anyone provide sample code of how to do this?

I recently checked if scripting works the same way under CE, and I made
up this little program to try it out. It should compile under EVC and
VC++.
It creates a JScript Engine and lets it calculate fib(10). Under CE the
output can seen in the de{*filter*} putput panel:

// BEGIN
// Code is broken at col 72. Please fix after pasting it into IDE.
#include <windows.h>
#include <activscp.h>
#include <stdio.h>
#include <stdarg.h>

#pragma comment (lib,"ole32")
#pragma comment (lib,"oleaut32")

#if UNDER_CE
#define wprintf nclog
void nclog(wchar_t *fmt, ...)
{
        wchar_t buf[256];
        va_list vl;
        va_start(vl,fmt);
        wvsprintf(buf,fmt,vl);
        OutputDebugString(buf);

Quote:
}

#endif

// MyScriptSite
// implements IActiveScriptSite and contains
// the IActiveScript Object.
class MyScriptSite : public IActiveScriptSite
{

        IActiveScript *m_as;
        IActiveScriptParse *m_asp;
        HRESULT m_hr;

        virtual ULONG STDMETHODCALLTYPE AddRef() { return 1; }
        virtual ULONG STDMETHODCALLTYPE Release() { return 1; }

        virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void
**p)
        {
                if ((iid==IID_IUnknown) || (iid==IID_IActiveScriptSite))
                {
                        *p=this;
                        AddRef();
                        return S_OK;
                }
                wprintf(L"QueryInterface?\n");

                return E_NOINTERFACE;
        }

    virtual HRESULT STDMETHODCALLTYPE GetLCID(
        LCID __RPC_FAR *plcid)
        {
                *plcid=LOCALE_USER_DEFAULT;
                return S_OK;
        }

    virtual HRESULT STDMETHODCALLTYPE GetItemInfo(
        LPCOLESTR pstrName,
        DWORD dwReturnMask,
        IUnknown __RPC_FAR *__RPC_FAR *ppiunkItem,
        ITypeInfo __RPC_FAR *__RPC_FAR *ppti)
        {
                wprintf(L"iteminfo? nope\n");
                return E_FAIL;
        }

    virtual HRESULT STDMETHODCALLTYPE GetDocVersionString(
        BSTR __RPC_FAR *pbstrVersion)
        {
                wprintf(L"getdocversionstring? nope\n");
                return E_FAIL;
        }

    virtual HRESULT STDMETHODCALLTYPE OnScriptTerminate(
        const VARIANT __RPC_FAR *pvarResult,
        const EXCEPINFO __RPC_FAR *pexcepinfo)
        {
                wprintf(L"Script Terminated\n");
                return S_OK;
        }

    virtual HRESULT STDMETHODCALLTYPE OnStateChange(
        SCRIPTSTATE ssScriptState)
        {
                wprintf(L"state=>%d\n",ssScriptState);
                return S_OK;
        }

    virtual HRESULT STDMETHODCALLTYPE OnScriptError(
        IActiveScriptError __RPC_FAR *pscripterror)
        {
                wprintf(L"Script Error\n");
                return S_OK;
        }

    virtual HRESULT STDMETHODCALLTYPE OnEnterScript( void)
        {
                wprintf(L"Enter Script\n");
                return S_OK;
        }

    virtual HRESULT STDMETHODCALLTYPE OnLeaveScript( void)
        {
                wprintf(L"Leave Script\n");
                return S_OK;
        }

public:

        MyScriptSite(OLECHAR* language=OLESTR("JScript")) : m_as(NULL),
m_asp(NULL)
        {
                CLSID clsid;
                m_hr=CLSIDFromProgID(language, &clsid);
                if (m_hr != S_OK) return;
                m_hr=CoCreateInstance(clsid,0,CLSCTX_ALL, IID_IActiveScript,
(void**)&m_as);
                if (m_hr!=S_OK) return;
                m_hr=m_as->SetScriptSite(this);
                if (m_hr!=S_OK) return;
                m_hr=m_as->QueryInterface(IID_IActiveScriptParse, (void**)
&m_asp);
                if (m_hr!=S_OK) return;
                m_hr=m_asp->InitNew();
                if (m_hr!=S_OK) return;
        }
        ~MyScriptSite()
        {
                if (m_as)
                {
                        m_hr=m_as->Close();
                        m_as->Release();
                }
                if (m_asp) m_asp->Release();
        }

        void run(OLECHAR *script,VARIANT &result)
        {
                VariantClear(&result);
                m_hr = m_asp->ParseScriptText(script, 0, 0, 0,
        0, 0, SCRIPTTEXT_ISEXPRESSION, &result, 0);
        }
        HRESULT status() { return m_hr; }

 };

void print(VARIANT &v)
{
        VARIANT s;
        VariantInit(&s);
        if (S_OK == VariantChangeType(&s,&v,0,VT_BSTR))
        {
                BSTR bs=V_BSTR(&s);
                wprintf(L"result:%s\n",bs);
        }
        else
                wprintf(L"dunno\n");
        VariantClear(&s);

Quote:
}

#if UNDER_CE

int WINAPI WinMain(HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPTSTR    lpCmdLine,
                    int       nCmdShow)
{
        CoInitializeEx(NULL,COINIT_MULTITHREADED);

#else

int main()
{
        CoInitialize(NULL);
#endif

        MyScriptSite mss;
        if (mss.status() == S_OK)
        {
                wprintf(L"ok..\n");
                VARIANT v; VariantInit(&v);
                long st=GetTickCount();

                mss.run(L"function fib(n){return (n<2)?1:(fib(n-2)+fib(n-
1));}\nfib(10);",v);

                long et=GetTickCount();
                wprintf(L"Time: %d msec\n",(et-st));
                wprintf(L"Status: %d\n", mss.status());
                print(v);
                return 1;
        }
        return 0;

Quote:
}

//END

In the de{*filter*} panel, you should expect the following output if it
works:

ax.exe
oleaut32.dll
ole32.dll
coredll.dll
jscript.dll
QueryInterface?
QueryInterface?
pdm.dll
state=>5
ok..
Enter Script
Leave Script
Time: 110 msec
Status: 0
result:89
state=>4

--
Marco



Wed, 27 Aug 2003 00:27:56 GMT  
 Starting JScript engine from emVC++ 3.0 on CE 3.0
Marco?

Could you please make some sort of class around your source?
Could one make a scriptcontrol class for WINCE?
With the same properties and methotds as on the PC?

I have in my program the following class:

class advObject
{
public:
 advObject();
 ~advObject();
 void setpos( int x, int y ) { m_X = x; m_Y = y; }
 void setanim( LAnim* a ) { m_Anim = a; }
 LAnim* getanim( void ) { return m_Anim; }
 void update( void );
 void draw( void );
 int getxpos( void ) { return m_X; }
 int getypos( void ) { return m_Y; }
 int getframe( void ) { return m_Frame; }
 void setframe( int i ) { m_Frame = i; }
 void setcounter( int i ) { m_Counter = i; }
 int getcounter( void ) { return m_Counter; }
 void isfloater( void ) { m_Floater = true; }
 void isclimber( void ) { m_Climber = true; }
 void isbomb( void ) { if (!m_Bomb) { m_Bomb = true; m_BCount = 6 * 8; } }
 bool getbomb( void ) { return m_Bomb; }
 bool getfloat( void ) { return m_Floater; }
private:
 int m_X, m_Y;
 int m_Counter, m_BCount, m_Height;
 int m_Frame;
 bool m_Floater, m_Climber, m_Bomb;
 LAnim* m_Anim;

Quote:
};

How can i "publish" this class to the scriptengine?
I want to use all the properties and methods of the class in Jscript
Please help

Kaiton Buitendijk


Quote:


> >I'm looking to fire up a JScript engine, pass it the name of a local
> >JSscript file for it to execute, and wait until the execution is
> >finished. Can anyone provide sample code of how to do this?

> I recently checked if scripting works the same way under CE, and I made
> up this little program to try it out. It should compile under EVC and
> VC++.
> It creates a JScript Engine and lets it calculate fib(10). Under CE the
> output can seen in the de{*filter*} putput panel:

> // BEGIN
> // Code is broken at col 72. Please fix after pasting it into IDE.
> #include <windows.h>
> #include <activscp.h>
> #include <stdio.h>
> #include <stdarg.h>

> #pragma comment (lib,"ole32")
> #pragma comment (lib,"oleaut32")

> #if UNDER_CE
> #define wprintf nclog
> void nclog(wchar_t *fmt, ...)
> {
> wchar_t buf[256];
> va_list vl;
> va_start(vl,fmt);
> wvsprintf(buf,fmt,vl);
> OutputDebugString(buf);
> }
> #endif

> // MyScriptSite
> // implements IActiveScriptSite and contains
> // the IActiveScript Object.
> class MyScriptSite : public IActiveScriptSite
> {

> IActiveScript *m_as;
> IActiveScriptParse *m_asp;
> HRESULT m_hr;

> virtual ULONG STDMETHODCALLTYPE AddRef() { return 1; }
> virtual ULONG STDMETHODCALLTYPE Release() { return 1; }

> virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void
> **p)

> if ((iid==IID_IUnknown) || (iid==IID_IActiveScriptSite))
> {
> *p=this;
> AddRef();
> return S_OK;
> }
> wprintf(L"QueryInterface?\n");

> return E_NOINTERFACE;
> }

>     virtual HRESULT STDMETHODCALLTYPE
LCID(
>         LCID __RPC_FAR *plcid)
> {
> *plcid=LOCALE_USER_DEFAULT;
> return S_OK;
> }

>     virtual HRESULT STDMETHODCALLTYPE GetItemInfo(
>         LPCOLESTR pstrName,
>         DWORD dwReturnMask,
>         IUnknown __RPC_FAR *__RPC_FAR *ppiunkItem,
>         ITypeInfo __RPC_FAR *__RPC_FAR *ppti)
> {
> wprintf(L"iteminfo? nope\n");
> return E_FAIL;
> }

>     virtual HRESULT STDMETHODCALLTYPE GetDocVersionString(
>         BSTR __RPC_FAR *pbstrVersion)
> {
> wprintf(L"getdocversionstring? nope\n");
> return E_FAIL;
> }

>     virtual HRESULT STDMETHODCALLTYPE OnScriptTerminate(
>         const VARIANT __RPC_FAR *pvarResult,
>         const EXCEPINFO __RPC_FAR *pexcepinfo)
> {
> wprintf(L"Script Terminated\n");
> return S_OK;
> }

>     virtual HRESULT STDMETHODCALLTYPE OnStateChange(
>         SCRIPTSTATE ssScriptState)
> {
> wprintf(L

"state=>%d\n",ssScriptState);

- Show quoted text -

Quote:
> return S_OK;
> }

>     virtual HRESULT STDMETHODCALLTYPE
criptError(
>         IActiveScriptError __RPC_FAR *pscripterror)
> {
> wprintf(L"Script Error\n");
> return S_OK;
> }

>     virtual HRESULT STDMETHODCALLTYPE OnEnterScript( void)
> {
> wprintf(L"Enter Script\n");
> return S_OK;
> }

>     virtual HRESULT STDMETHODCALLTYPE OnLeaveScript( void)
> {
> wprintf(L"Leave Script\n");
> return S_OK;
> }

> public:

> MyScriptSite(OLECHAR* language=OLESTR("JScript")) : m_as(NULL),
> m_asp(NULL)
> {
> CLSID clsid;
> m_hr=CLSIDFromProgID(language, &clsid);
> if (m_hr != S_OK) return;
> m_hr=CoCreateInstance(clsid,0,CLSCTX_ALL, IID_IActiveScript,
> (void**)&m_as);
> if (m_hr!=S_OK) return;
> m_hr=m_as->SetScriptSite(this);
> if (m_hr!=S_OK) return;
> m_hr=m_as->QueryInterface(IID_IActiveScriptParse, (void**)
> &m_asp);
> if (m_hr!=S_OK) return;
> m_hr=m_asp->InitNew();
> if (m_hr!=S_OK) return;
> }
> ~MyScriptSite()
> {
> if (m_as)
> {
> m_hr=m_as->Close();
> m_as->Release();
> }
> if (m_asp) m_asp->Release();
> }

> void run(OLECHAR *script,VARIANT &result)
> {
> VariantClear(&result);
> m_hr = m_asp->ParseScriptText(script, 0, 0, 0,
>         0, 0, SCRIPTTEXT_ISEXPRESSION, &result, 0);
> }
> HRESULT status() { return m_hr; }

>  };

> void print(VARIANT &v)
> {
> VARIANT s;
> VariantInit(&s);
> if (S_OK == VariantChangeType(&s,&v,0,VT_BSTR))
> {
> BSTR bs=V_BSTR(&s);
> wprintf(L"result:%s\n",bs);
> }
> else
> wprintf(L"dunno\n");
> VariantClear(&s);
> }

> #if UNDER_CE

> int WINAPI WinMain(HINSTANCE hInstance,
>                     HINSTANCE hPrevInstance,
>                     LPTSTR    lpCmdLine,
>                     int       nCmdShow)
> {
> CoInitializeEx(NULL,COINIT_MULTITHREADED);

> #else

> int main()
> {
> CoInitialize(NULL);
> #endif

> MyScriptSite mss;
> if (mss.status() == S_OK)
> {
> wpr
intf(L"ok..\n");
> VARIANT v; VariantInit(&v);
> long st=GetTickCount();

>         mss.run(L"function fib(n){return (n<2)?1:(fib(n-2)+fib(n-
> 1));}\nfib(10);",v);

> long et=GetTickCount();
> wprintf(L"Time: %d msec\n",(et-st));
> wprintf(L"Status: %d\n", mss.status());
> print(v);
> return 1;
> }
> return 0;
> }

> file://END

> In the de{*filter*} panel, you should expect the following output if it
> works:

> ax.exe
> oleaut32.dll
> ole32.dll
> coredll.dll
> jscript.dll
> QueryInterface?
> QueryInterface?
> pdm.dll
> state=>5
> ok..
> Enter Script
> Leave Script
> Time: 110 msec
> Status: 0
> result:89
> state=>4

> --
> Marco



Sat, 30 Aug 2003 21:12:31 GMT  
 Starting JScript engine from emVC++ 3.0 on CE 3.0
Please refer to the MSDN documentation for ActiveScripting there is a
significant amount of information there including samples.

--
Steve Maillet
Entelechy Software Consulting
smaillet 'AT' EntelechyConsulting 'DOT' com
http://www.*-*-*.com/

Quote:
> Marco?

> Could you please make some sort of class around your source?
> Could one make a scriptcontrol class for WINCE?
> With the same properties and methotds as on the PC?

> I have in my program the following class:

> class advObject
> {
> public:
>  advObject();
>  ~advObject();
>  void setpos( int x, int y ) { m_X = x; m_Y = y; }
>  void setanim( LAnim* a ) { m_Anim = a; }
>  LAnim* getanim( void ) { return m_Anim; }
>  void update( void );
>  void draw( void );
>  int getxpos( void ) { return m_X; }
>  int getypos( void ) { return m_Y; }
>  int getframe( void ) { return m_Frame; }
>  void setframe( int i ) { m_Frame = i; }
>  void setcounter( int i ) { m_Counter = i; }
>  int getcounter( void ) { return m_Counter; }
>  void isfloater( void ) { m_Floater = true; }
>  void isclimber( void ) { m_Climber = true; }
>  void isbomb( void ) { if (!m_Bomb) { m_Bomb = true; m_BCount = 6 * 8; } }
>  bool getbomb( void ) { return m_Bomb; }
>  bool getfloat( void ) { return m_Floater; }
> private:
>  int m_X, m_Y;
>  int m_Counter, m_BCount, m_Height;
>  int m_Frame;
>  bool m_Floater, m_Climber, m_Bomb;
>  LAnim* m_Anim;
> };

> How can i "publish" this class to the scriptengine?
> I want to use all the properties and methods of the class in Jscript
> Please help

> Kaiton Buitendijk





> > >I'm looking to fire up a JScript engine, pass it the name of a local
> > >JSscript file for it to execute, and wait until the execution is
> > >finished. Can anyone provide sample code of how to do this?

> > I recently checked if scripting works the same way under CE, and I made
> > up this little program to try it out. It should compile under EVC and
> > VC++.
> > It creates a JScript Engine and lets it calculate fib(10). Under CE the
> > output can seen in the de{*filter*} putput panel:

> > // BEGIN
> > // Code is broken at col 72. Please fix after pasting it into IDE.
> > #include <windows.h>
> > #include <activscp.h>
> > #include <stdio.h>
> > #include <stdarg.h>

> > #pragma comment (lib,"ole32")
> > #pragma comment (lib,"oleaut32")

> > #if UNDER_CE
> > #define wprintf nclog
> > void nclog(wchar_t *fmt, ...)
> > {
> > wchar_t buf[256];
> > va_list vl;
> > va_start(vl,fmt);
> > wvsprintf(buf,fmt,vl);
> > OutputDebugString(buf);
> > }
> > #endif

> > // MyScriptSite
> > // implements IActiveScriptSite and contains
> > // the IActiveScript Object.
> > class MyScriptSite : public IActiveScriptSite
> > {

> > IActiveScript *m_as;
> > IActiveScriptParse *m_asp;
> > HRESULT m_hr;

> > virtual ULONG STDMETHODCALLTYPE AddRef() { return 1; }
> > virtual ULONG STDMETHODCALLTYPE Release() { return 1; }

> > virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void
> > **p)

> > if ((iid==IID_IUnknown) || (iid==IID_IActiveScriptSite))
> > {
> > *p=this;
> > AddRef();
> > return S_OK;
> > }
> > wprintf(L"QueryInterface?\n");

> > return E_NOINTERFACE;
> > }

> >     virtual HRESULT STDMETHODCALLTYPE
> LCID(
> >         LCID __RPC_FAR *plcid)
> > {
> > *plcid=LOCALE_USER_DEFAULT;
> > return S_OK;
> > }

> >     virtual HRESULT STDMETHODCALLTYPE GetItemInfo(
> >         LPCOLESTR pstrName,
> >         DWORD dwReturnMask,
> >         IUnknown __RPC_FAR *__RPC_FAR *ppiunkItem,
> >         ITypeInfo __RPC_FAR *__RPC_FAR *ppti)
> > {
> > wprintf(L"iteminfo? nope\n");
> > return E_FAIL;
> > }

> >     virtual HRESULT STDMETHODCALLTYPE GetDocVersionString(
> >         BSTR __RPC_FAR *pbstrVersion)
> > {
> > wprintf(L"getdocversionstring? nope\n");
> > return E_FAIL;
> > }

> >     virtual HRESULT STDMETHODCALLTYPE OnScriptTerminate(
> >         const VARIANT __RPC_FAR *pvarResult,
> >         const EXCEPINFO __RPC_FAR *pexcepinfo)
> > {
> > wprintf(L"Script Terminated\n");
> > return S_OK;
> > }

> >     virtual HRESULT STDMETHODCALLTYPE OnStateChange(
> >         SCRIPTSTATE ssScriptState)
> > {
> > wprintf(L
> "state=>%d\n",ssScriptState);
> > return S_OK;
> > }

> >     virtual HRESULT STDMETHODCALLTYPE
> criptError(
> >         IActiveScriptError __RPC_FAR *pscripterror)
> > {
> > wprintf(L"Script Error\n");
> > return S_OK;
> > }

> >     virtual HRESULT STDMETHODCALLTYPE OnEnterScript( void)
> > {
> > wprintf(L"Enter Script\n");
> > return S_OK;
> > }

> >     virtual HRESULT STDMETHODCALLTYPE OnLeaveScript( void)
> > {
> > wprintf(L"Leave Script\n");
> > return S_OK;
> > }

> > public:

> > MyScriptSite(OLECHAR* language=OLESTR("JScript")) : m_as(NULL),
> > m_asp(NULL)
> > {
> > CLSID clsid;
> > m_hr=CLSIDFromProgID(language, &clsid);
> > if (m_hr != S_OK) return;
> > m_hr=CoCreateInstance(clsid,0,CLSCTX_ALL, IID_IActiveScript,
> > (void**)&m_as);
> > if (m_hr!=S_OK) return;
> > m_hr=m_as->SetScriptSite(this);
> > if (m_hr!=S_OK) return;
> > m_hr=m_as->QueryInterface(IID_IActiveScriptParse, (void**)
> > &m_asp);
> > if (m_hr!=S_OK) return;
> > m_hr=m_asp->InitNew();
> > if (m_hr!=S_OK) return;
> > }
> > ~MyScriptSite()
> > {
> > if (m_as)
> > {
> > m_hr=m_as->Close();
> > m_as->Release();
> > }
> > if (m_asp) m_asp->Release();
> > }

> > void run(OLECHAR *script,VARIANT &result)
> > {
> > VariantClear(&result);
> > m_hr = m_asp->ParseScriptText(script, 0, 0, 0,
> >         0, 0, SCRIPTTEXT_ISEXPRESSION, &result, 0);
> > }
> > HRESULT status() { return m_hr; }

> >  };

> > void print(VARIANT &v)
> > {
> > VARIANT s;
> > VariantInit(&s);
> > if (S_OK == VariantChangeType(&s,&v,0,VT_BSTR))
> > {
> > BSTR bs=V_BSTR(&s);
> > wprintf(L"result:%s\n",bs);
> > }
> > else
> > wprintf(L"dunno\n");
> > VariantClear(&s);
> > }

> > #if UNDER_CE

> > int WINAPI WinMain(HINSTANCE hInstance,
> >                     HINSTANCE hPrevInstance,
> >                     LPTSTR    lpCmdLine,
> >                     int       nCmdShow)
> > {
> > CoInitializeEx(NULL,COINIT_MULTITHREADED);

> > #else

> > int main()
> > {
> > CoInitialize(NULL);
> > #endif

> > MyScriptSite mss;
> > if (mss.status() == S_OK)
> > {
> > wpr
> intf(L"ok..\n");
> > VARIANT v; VariantInit(&v);
> > long st=GetTickCount();

> >         mss.run(L"function fib(n){return (n<2)?1:(fib(n-2)+fib(n-
> > 1));}\nfib(10);",v);

> > long et=GetTickCount();
> > wprintf(L"Time: %d msec\n",(et-st));
> > wprintf(L"Status: %d\n", mss.status());
> > print(v);
> > return 1;
> > }
> > return 0;
> > }

> > file://END

> > In the de{*filter*} panel, you should expect the following output if it
> > works:

> > ax.exe
> > oleaut32.dll
> > ole32.dll
> > coredll.dll
> > jscript.dll
> > QueryInterface?
> > QueryInterface?
> > pdm.dll
> > state=>5
> > ok..
> > Enter Script
> > Leave Script
> > Time: 110 msec
> > Status: 0
> > result:89
> > state=>4

> > --
> > Marco



Sat, 30 Aug 2003 22:37:28 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. CEF Plug-in for eMVC++ 3.0 install error

2. Why no STL support in emVC++ 3.0?

3. Periodic timer functions in eMVC 3.0

4. emVC 3.0 DLL project does not produce .lib file

5. CE 3.0 application in CE.NET platform

6. MFC CE 2.11 vs. MFC CE 3.0 compatibility

7. MFC Application for CE 2.11 on CE 3.0

8. CE toolkit support for CE 3.0

9. Help! CE 3.0 vs CE .NET newbie questions

10. How to create VC6 desktop project from emvC++ 3.0 project?

11. PPC 2002, WinCE 3.0, eVC++ 3.0, loading images in HTML viewer control

12. evc 3.0 & adoce 3.0

 

 
Powered by phpBB® Forum Software