本文整理汇总了C++中CComObject::AddScript方法的典型用法代码示例。如果您正苦于以下问题:C++ CComObject::AddScript方法的具体用法?C++ CComObject::AddScript怎么用?C++ CComObject::AddScript使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CComObject
的用法示例。
在下文中一共展示了CComObject::AddScript方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
String
ScriptServer::Compile_(const String &sLanguage, const String &sFilename)
{
String sContents = FileUtilities::ReadCompleteTextFile(sFilename);
if (sContents.IsEmpty())
return "";
// Create an instance of the script engine and execute the script.
CComObject<CScriptSiteBasic>* pBasic;
CComObject<CScriptSiteBasic>::CreateInstance(&pBasic);
CComQIPtr<IActiveScriptSite> spUnk;
if (!pBasic)
return "ScriptServer:: Failed to create instance of script site.";
spUnk = pBasic; // let CComQIPtr tidy up for us
pBasic->Initiate(sLanguage, NULL);
// pBasic->SetObjectContainer(pObjects);
pBasic->AddScript(sContents);
pBasic->Run();
pBasic->Terminate();
String sErrorMessage = pBasic->GetLastError();
if (!sErrorMessage.IsEmpty())
sErrorMessage = "File: " + sFilename + "\r\n" + sErrorMessage;
return sErrorMessage;
}
示例2: if
void
ScriptServer::FireEvent(Event e, const String &sEventCaller, std::shared_ptr<ScriptObjectContainer> pObjects)
{
if (!Configuration::Instance()->GetUseScriptServer())
return;
// JDR: stores the name of the method that is fired in the script. http://www.hmailserver.com/forum/viewtopic.php?f=2&t=25497
String event_name_ = _T("Unknown");
switch (e)
{
case EventOnClientConnect:
event_name_ = _T("OnClientConnect");
if (!has_on_client_connect_)
return;
break;
case EventOnAcceptMessage:
event_name_ = _T("OnAcceptMessage");
if (!has_on_accept_message_)
return;
break;
case EventOnMessageDeliver:
event_name_ = _T("OnMessageDeliver");
if (!has_on_deliver_message_)
return;
break;
case EventOnBackupCompleted:
event_name_ = _T("OnBackupCompleted");
if (!has_on_backup_completed_)
return;
break;
case EventOnBackupFailed:
event_name_ = _T("OnBackupFailed");
if (!has_on_backup_failed_)
return;
break;
case EventOnError:
event_name_ = _T("OnError");
if (!has_on_error_)
return;
break;
case EventOnDeliveryStart:
event_name_ = _T("OnDeliveryStart");
if (!has_on_delivery_start_)
return;
break;
case EventOnDeliveryFailed:
event_name_ = _T("OnDeliveryFailed");
if (!has_on_delivery_failed_)
return;
break;
case EventOnExternalAccountDownload:
event_name_ = _T("OnExternalAccountDownload");
if (!has_on_external_account_download_)
return;
break;
case EventOnSMTPData:
event_name_ = _T("OnSMTPData");
if (!has_on_smtpdata_)
return;
break;
case EventCustom:
break;
default:
{
return;
}
}
LOG_DEBUG("Executing event " + event_name_);
String sScript;
// Build the script.
if (script_language_ == _T("VBScript"))
sScript = script_contents_ + "\r\n\r\n" + "Call " + sEventCaller + "\r\n";
else if (script_language_ == _T("JScript"))
sScript = script_contents_ + "\r\n\r\n" + sEventCaller + ";\r\n";
CComObject<CScriptSiteBasic>* pBasic;
CComObject<CScriptSiteBasic>::CreateInstance(&pBasic);
CComQIPtr<IActiveScriptSite> spUnk;
if (!pBasic)
{
ErrorManager::Instance()->ReportError(ErrorManager::High, 5018, "ScriptServer::FireEvent", "Failed to create instance of script site.");
return;
}
spUnk = pBasic; // let CComQIPtr tidy up for us
pBasic->Initiate(script_language_, NULL);
pBasic->SetObjectContainer(pObjects);
pBasic->AddScript(sScript);
pBasic->Run();
pBasic->Terminate();
LOG_DEBUG("Event completed");
//.........这里部分代码省略.........
示例3: if
void
ScriptServer::FireEvent(Event e, const String &sEventCaller, shared_ptr<ScriptObjectContainer> pObjects)
{
if (!Configuration::Instance()->GetUseScriptServer())
return;
// JDR: stores the name of the method that is fired in the script. http://www.hmailserver.com/forum/viewtopic.php?f=2&t=25497
String m_sEventName = _T("Unknown");
switch (e)
{
case EventOnClientConnect:
m_sEventName = _T("OnClientConnect");
if (!m_bHasOnClientConnect)
return;
break;
case EventOnAcceptMessage:
m_sEventName = _T("OnAcceptMessage");
if (!m_bHasOnAcceptMessage)
return;
break;
case EventOnMessageDeliver:
m_sEventName = _T("OnMessageDeliver");
if (!m_bHasOnDeliverMessage)
return;
break;
case EventOnBackupCompleted:
m_sEventName = _T("OnBackupCompleted");
if (!m_bHasOnBackupCompleted)
return;
break;
case EventOnBackupFailed:
m_sEventName = _T("OnBackupFailed");
if (!m_bHasOnBackupFailed)
return;
break;
case EventOnError:
m_sEventName = _T("OnError");
if (!m_bHasOnError)
return;
break;
case EventOnDeliveryStart:
m_sEventName = _T("OnDeliveryStart");
if (!m_bHasOnDeliveryStart)
return;
break;
case EventOnDeliveryFailed:
m_sEventName = _T("OnDeliveryFailed");
if (!m_bHasOnDeliveryFailed)
return;
break;
case EventOnExternalAccountDownload:
m_sEventName = _T("OnExternalAccountDownload");
if (!m_bHasOnExternalAccountDownload)
return;
break;
case EventOnSMTPData:
m_sEventName = _T("OnSMTPData");
if (!m_bHasOnSMTPData)
return;
break;
case EventCustom:
break;
default:
{
return;
}
}
// JDR: Added event name to the debug log. http://www.hmailserver.com/forum/viewtopic.php?f=2&t=25497
LOG_DEBUG("ScriptServer::FireEvent-" + m_sEventName);
String sScript;
// Build the script.
if (m_sScriptLanguage == _T("VBScript"))
sScript = m_sScriptContents + "\r\n\r\n" + "Call " + sEventCaller + "\r\n";
else if (m_sScriptLanguage == _T("JScript"))
sScript = m_sScriptContents + "\r\n\r\n" + sEventCaller + ";\r\n";
CComObject<CScriptSiteBasic>* pBasic;
CComObject<CScriptSiteBasic>::CreateInstance(&pBasic);
CComQIPtr<IActiveScriptSite> spUnk;
if (!pBasic)
{
ErrorManager::Instance()->ReportError(ErrorManager::High, 5018, "ScriptServer::FireEvent", "Failed to create instance of script site.");
return;
}
spUnk = pBasic; // let CComQIPtr tidy up for us
pBasic->Initiate(m_sScriptLanguage, NULL);
pBasic->SetObjectContainer(pObjects);
pBasic->AddScript(sScript);
pBasic->Run();
pBasic->Terminate();
LOG_DEBUG("ScriptServer:~FireEvent");
//.........这里部分代码省略.........