void ScriptEngine::AddCode(LPTSTR strCode)
	{
		HRESULT hr = _ptr->AddCode(
			_bstr_t(strCode)	//[in] BSTR Code
			);
		GetMethodsName();
	}
Пример #2
0
///////////////////////////////////////////////////////////////////////////////
// LoadScript
//		Load a Script File.  This function loads and insert all functions and
//		procedures to the component.  The script file may contain comments as well.
//		Global variables may also be define. You may want to see the script file
//		as a Module file in Visual Basic.
//		The script file is probably a simple text file (ASCII format)
///////////////////////////////////////////////////////////////////////////////
bool CScriptObject::LoadScript(LPCTSTR szFilename)
{
	HANDLE hFile = CreateFile(szFilename, GENERIC_READ, FILE_SHARE_READ,
			NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (hFile != INVALID_HANDLE_VALUE)
	{
		DWORD dwSize = GetFileSize(hFile, NULL);
		if (0xFFFFFFFF != dwSize)
		{
			BYTE* pbytes = (BYTE*) GlobalAlloc(GPTR, dwSize+1);
			if (pbytes != NULL)
			{
				DWORD dwRead = 0;
				bool bResult = false;
				if (ReadFile(hFile, pbytes, dwSize, &dwRead, NULL))
				{
					try{
						if (m_pScript)
						{
							_bstr_t strCode = (LPCSTR) (pbytes);
							m_pScript->AddCode( strCode );
							GetMethodsName();
							bResult = true;
						}
					}
					catch(...)
					{
						// Just catch the exception, call GetErrorString()
						// to retreive last error
					}

					GlobalFree( (HGLOBAL) pbytes);
					CloseHandle(hFile);
					return bResult;
				}

				GlobalFree( (HGLOBAL) pbytes);
			}
		}

		CloseHandle(hFile);
		return false;
	}

	return false;
}
Пример #3
0
///////////////////////////////////////////////////////////////////////////////
// AddScript
//		Use this function to add a script function, useful for internal use
//		not global script (resource file).
///////////////////////////////////////////////////////////////////////////////
bool CScriptObject::AddScript(LPCTSTR szCode)
{
	try {
		if (m_pScript != NULL)
		{
			ULONG ref = m_pScript->AddRef();
			_bstr_t strCode = szCode;
			m_pScript->AddCode( strCode );
			GetMethodsName();
			ref = m_pScript->Release();
			return true;
		}
	}
	catch(...)
	{
		// Just catch the exception, call GetErrorString()
		// to retreive last error
		ULONG ref = m_pScript->Release();
	}
	return false;
}
Пример #4
0
//////////////////////////////////////////////////////////////////////////
// LoadScriptResource:
//		Load a Script resource.  This function loads and insert all functions
//		and procedures to the component.  The script resource may contain comments
//		as well.  Global variables may also be defined. You may want to see the
//		script resource as a Module file in Visual Basic.
//////////////////////////////////////////////////////////////////////////
bool CScriptObject::LoadScriptResource(LPCTSTR lpName, LPCTSTR lpType, HINSTANCE hInstance )
{
	try{
		if (m_pScript)
		{
			HRSRC res = ::FindResource(hInstance, lpName, lpType);
			ASSERT( res != NULL);
			BYTE* pbytes = (BYTE*) LockResource(LoadResource(hInstance, res ));
			ASSERT( pbytes != NULL);
			_bstr_t strCode = (LPCSTR) (pbytes);
			m_pScript->AddCode( strCode );
			GetMethodsName();
			return true;
		}
	}
	catch(...)
	{
		// Just catch the exception, call GetErrorString()
		// to retreive last error
	}
	return false;
}