SimpleScript Part Seven: Binder Skeleton

In Part Five I was discussing modules: there is a “global module” and any number of additional modules.  Each module is associated with a named item, and the only module which is associated with more than one named item is the global module.  This means that each module is going to need its own name…

17

invoke.cpp

#include “headers.h” HRESULT InvokeDispatch(IDispatch * pdisp, DISPID dispid, REFIID riid,    LCID lcid, WORD flags, DISPPARAMS * pDispParams, VARIANT * pvarResult,    EXCEPINFO * pExcepInfo, UINT * pError){    AssertReadPtr(pdisp);     HRESULT hr;     // We must addref the pointer before the invocation.  Why?  Consider    // this scenario:  the invocation calls a method which calls back    // into…

0

invoke.h

#ifndef INVOKE_H // {#define INVOKE_H extern HRESULT InvokeDispatch(IDispatch * pdisp, DISPID dispid, REFIID riid,    LCID lcid, WORD flags, DISPPARAMS * pDispParams, VARIANT * pvarResult,    EXCEPINFO * pExcepInfo, UINT * pError); extern BOOL IsValidDispatch(VARIANT * pvar); #endif // INVOKE_H }

0

binder.cpp

#include “headers.h” Binder::Binder(){    DLLAddRef();    this->m_cref = 1;    this->m_thread = GetCurrentThreadId();} Binder::~Binder(void){    DLLRelease();} HRESULT Binder::Create(Binder * * ppBinder){    AssertOutPtr(ppBinder);     *ppBinder = new Binder();    if (NULL == *ppBinder)        return E_OUTOFMEMORY;     return S_OK;} // IUnknown STDMETHODIMP_(ULONG) Binder::AddRef(void){    return InterlockedIncrement(&this->m_cref);} STDMETHODIMP_(ULONG) Binder::Release(void){    long cref = InterlockedDecrement(&this->m_cref);    if (0 == cref)        delete this;    return cref;} STDMETHODIMP Binder::QueryInterface(REFIID riid,…

1

binder.h

#ifndef BINDER_H // {#define BINDER_H class Binder : public IDispatch{ protected:     class Name    {    public:         Name();        ~Name();                HRESULT SetValue(VARIANTARG * pvar);        HRESULT GetValue(VARIANT * pvar);        BOOL IsFunction(void);        HRESULT ExecuteFunction(UINT cArgs, VARIANTARG * rgvarArgs, VARIANT * pvarResult);         VARIANT m_var;    }; public:     static HRESULT Create(Binder * * ppBinder);     // IUnknown    STDMETHOD(QueryInterface)(REFIID…

0

SimpleScript Part Six: Threading Technicalities

Refresher Course Before you read this, you might want to take a quick refresher on my original posting on the script engine threading model.  That was a somewhat simplified (!) description of the actual script engine contract.  Let me just sum up: free threaded objects can be called from any thread at any time; the…

19

SimpleScript Part Five: Named Items and Modules

Named Items “Named items” are what we call the “top level” objects of the host provided object model.  WScript in WSH, window in Internet Explorer, Response in ASP, are all named items.  A host tells an initialized script engine about named items via the aptly named AddNamedItem method on the IActiveScript interface. HRESULT ScriptEngine::AddNamedItem(const WCHAR…

16

nameditemlist.h

#ifndef NAMEDITEMLIST_H // {#define NAMEDITEMLIST_H class NamedItemList{ private:     class NamedItem    {    private:         NamedItem();     public:         ~NamedItem();        static HRESULT Create(const WCHAR * pszName, NamedItem * * ppNamedItem);            NamedItem * m_pNext;         BSTR m_bstrName;        DWORD m_flags;         BOOL IsPersistent();        void Reset();    };     NamedItemList();    NamedItem * Find(const WCHAR * psz);    Mutex * m_pMutex;   …

0

nameditemlist.cpp

#include “headers.h” NamedItemList::NamedItemList(){    this->m_cBuckets = 0;    this->m_Buckets = NULL;    this->m_pMutex = NULL;} NamedItemList::~NamedItemList(){    this->Clear();    if (NULL != this->m_Buckets)        delete[] this->m_Buckets;    if (NULL != this->m_pMutex)        delete this->m_pMutex;} HRESULT NamedItemList::Create(int cBuckets, NamedItemList * * ppNamedItemList){    AssertOutPtr(ppNamedItemList);    Assert(cBuckets > 0);     HRESULT hr;    int iBucket;    NamedItemList * pNamedItemList = NULL;     *ppNamedItemList = NULL;     pNamedItemList = new…

1

mutex.cpp

#include “headers.h” Mutex::Mutex(){    m_fInitialized = FALSE;} HRESULT Mutex::Create(Mutex * * ppMutex){    AssertOutPtr(ppMutex);     HRESULT hr;    BOOL fSuccess;    DWORD error;    Mutex * pMutex = NULL;     pMutex = new Mutex();    if (NULL == pMutex)    {        hr = E_OUTOFMEMORY;        goto LError;    }     fSuccess = InitializeCriticalSectionAndSpinCount(&pMutex->m_criticalsection, 0);    if (!fSuccess)    {        error = GetLastError();        hr = HRESULT_FROM_WIN32(error);        goto…

0