Exemple #1
0
void CPigEngine::RemoveInvokeCommands(CPigBehaviorScriptType* pType)
{
  // Get the collection of invoke commands for the object
  ITCStringsPtr spInvokeCommands;
  _SVERIFYE(pType->get_InvokeCommands(&spInvokeCommands));
  assert(NULL != spInvokeCommands);

  // Iterate through each one and erase it from the map
  long cInvokeCommands = 0;
  _SVERIFYE(spInvokeCommands->get_Count(&cInvokeCommands));
  XLock lock(this);
  for (_variant_t i(0L); V_I4(&i) < cInvokeCommands; ++V_I4(&i))
  {
    CComBSTR bstrCommand;
    _SVERIFYE(spInvokeCommands->get_Item(&i, &bstrCommand));
    USES_CONVERSION;
    tstring strCommand(OLE2CT(bstrCommand));
    XBehaviorMapIt it = m_mapBehaviors.find(strCommand);
    if (m_mapBehaviors.end() != it)
    {
      it->second->Release();
      m_mapBehaviors.erase(it);
    }
  }
}
void CFilePosterDlg::OnButton1() 
{
	char pzBuf[512];
	GetTempPath(512,pzBuf);
	GString strTempFile ( pzBuf );
	if ( strTempFile.GetAt(strTempFile.GetLength() - 1) != '\\')
		strTempFile << "\\";
	strTempFile << "FilePoster.Notes.txt";

	UnpackNotes(strTempFile);

	GString strCommand("notepad.exe ");
	strCommand << strTempFile;

	PROCESS_INFORMATION pInfo;
	STARTUPINFO         sInfo;

	sInfo.cb              = sizeof(STARTUPINFO);
	sInfo.lpReserved      = NULL;
	sInfo.lpReserved2     = NULL;
	sInfo.cbReserved2     = 0;
	sInfo.lpDesktop       = NULL;
	sInfo.lpTitle         = NULL;
	sInfo.dwFlags         = 0;
	sInfo.dwX             = 0;
	sInfo.dwY             = 0;
	sInfo.dwFillAttribute = 0;
	sInfo.wShowWindow     = SW_SHOW;
	CreateProcess(NULL, (char *)(const char *)strCommand, NULL, NULL, FALSE, 0,NULL, NULL, &sInfo, &pInfo);
	
}
///////////////////////////////////////////////////////////////////////////////
// ProcessAppCommand
BOOL CXHTMLStatic::ProcessAppCommand(LPCTSTR lpszCommand)
{
	TRACE(_T("in CXHTMLStatic::ProcessAppCommand:  %s\n"), lpszCommand);

	BOOL bRet = FALSE;

	CString strCommand(lpszCommand);
	if (strCommand[0] == _T('"'))
		strCommand = strCommand.Mid(1);
	if (strCommand[strCommand.GetLength()-1] == _T('"'))
		strCommand = strCommand.Left(strCommand.GetLength()-1);

	if ((m_nAppCommands > 0) && (m_paAppCommands != NULL))
	{
		for (int i = 0; i < m_nAppCommands; i++)
		{
			if (_tcsicmp(m_paAppCommands[i].pszCommand, strCommand) == 0)
			{
				TRACE(_T("found app command %s\n"), strCommand);
				if (m_paAppCommands[i].hWnd &&
					::IsWindow(m_paAppCommands[i].hWnd))
				{
					::SendMessage(m_paAppCommands[i].hWnd, 
								  m_paAppCommands[i].uMessage, 
								  m_paAppCommands[i].wParam,
								  0);
					bRet = TRUE;
					break;
				}
			}
		}
	}

	return bRet;
}
Exemple #4
0
void CsocketClient::OnReceive(int nErrorCode)
{
	const int iBufferSize = 16384;
	char strBuf[iBufferSize + 1];

	while (_IsDataAvailable())
	{
		int iReceived = Receive(strBuf, iBufferSize);
		if ((iReceived == SOCKET_ERROR) || (iReceived == 0))	// Disconnect (BUSY) causes 0 to be returned?
		{
			break;
		}

		strBuf[iReceived] = '\0';

		CString str(strBuf);

		m_strBuffer += str;

		int iIndexCR = m_strBuffer.Find(_T('\r'));
		int iIndexLF = m_strBuffer.Find(_T('\n'));

		int iIndex = -1, iIndexLast = -1;

		if ((iIndexLF > -1) && (iIndexCR > -1))
		{
			iIndex = min(iIndexLF, iIndexCR);
			iIndexLast = max(iIndexLF, iIndexCR);
		}
		else if ((iIndexCR > -1) || (iIndexLF > -1))
		{
			iIndex = iIndexLast = max(iIndexCR, iIndexLF);
		}

		if (iIndex == -1)
			continue;

		CString strCommand(m_strBuffer.Left(iIndex));

		if (m_pCallback)
			m_pCallback->OnCommand(this, strCommand);

		m_strBuffer = m_strBuffer.Mid(iIndexLast + 1);
	}

	CSocket::OnReceive(nErrorCode);
}
Exemple #5
0
int main(int argc, char **argv)
{
  AString strCommand(argv[1]);
  try
  {
    if (strCommand.equalsNoCase("install"))
    {
      if (installService())
        std::cout << "Service installed." << std::endl;
      else
        std::cout << "Service install failed." << std::endl;
    }
    else if (strCommand.equalsNoCase("remove"))
    {
      if (removeService())
        std::cout << "Service removed." << std::endl;
      else
        std::cout << "Service remove failed." << std::endl;
    }
    else
    {
      // When service dispatch action is requested this main() is called with no parameters
      // This connects the handler with service
      connectToServiceDispatch();
    }
  }
  catch(AException& ex)
  {
    AFILE_TRACER_DEBUG_MESSAGE((AString("main: ")+ex.what()).c_str(), NULL);
    std::cerr << ex.what() << std::endl;
  }
  catch(std::exception& ex)
  {
    AFILE_TRACER_DEBUG_MESSAGE((AString("main: ")+ex.what()).c_str(), NULL);
    std::cerr << ex.what() << std::endl;
  }
  catch(...)
  {
    AFILE_TRACER_DEBUG_MESSAGE("main: Unknown exception", NULL);
    std::cerr << "Unknown exception" << std::endl;
  }

  return 1;
}
Exemple #6
0
void BTCMessage::SetCommand(const char *szCommand)
{
	int iLen = strlen(szCommand);	// length of ascii string of command
	if (iLen>=sizeof(chCommand))
		iLen=sizeof(chCommand);		// can't be too long !
	else
		memset(chCommand+iLen, 0, sizeof(chCommand)-iLen);	// zero padding of remaing bytes, otherwise invalid
	memcpy(chCommand, szCommand, iLen);
	std::string strCommand(" ");		// space in front
	strCommand += szCommand;
	strCommand += ' ';					// space in back
	size_t p = BTCMsgCommandsString.find(strCommand);
	if (p==std::string::npos)  // command passed not found
		iCommand = btcmsg_unknown;
	else
		iCommand = (enum BTCMsgCommands) (BTCMsgCommandsString[p-1]-48+(BTCMsgCommandsString[p-2]-48)*10);
	iMsgStatus=btcmsgstat_command;
	SetPayloadChkStatus();
}
Exemple #7
0
/*
 * Sends a command to the Maya command port. Connects to the command port
 * if not already connected. The result returned by Maya is stored as a
 * string in the m_strReply member variable, to be potentially processed
 * later by the get_Result() member function.
 *
 * Parameters
 *   Command [in] Null-terminated string with the command.
 *
 * Return Value
 *   Returns S_OK if successful, or an error value otherwise.
 *
 * Remarks
 *   The return value from this method only indicates whether the command
 *   was successfully sent to the Maya command port. It does not indicate
 *   if the command was successfully executed by Maya.
 */
STDMETHODIMP CMELCommand::Execute(BSTR Command)
{
	m_strResult.Empty();

	HRESULT hr = Connect();
	if (FAILED(hr))
		return hr;

	// convert BSTR to ANSI
	CAtlString strCommand(Command);
	CW2A pszCommand(strCommand);

	// send command to Maya command port
	int err = send(m_socket, pszCommand, (int)strlen(pszCommand), 0);
	if (err == SOCKET_ERROR)
	{
		Disconnect();
		return AtlReportError(GetObjectCLSID(),
			L"Unable to send command to command port",
			IID_IMELCommand);
	}

	// wait for reply, store result as raw string
	char* recvBuf = new char[4096+1];
	int numBytes = recv(m_socket, recvBuf, 4096, 0);
	if (numBytes == SOCKET_ERROR)
	{
		delete[] recvBuf;
		Disconnect();
		return AtlReportError(GetObjectCLSID(),
			L"Unable to get reply from command port",
			IID_IMELCommand);
	}
	recvBuf[numBytes] = '\0'; // practising safe string usage
	CA2W pszRecv(recvBuf); // convert ANSI to Unicode
	m_strResult = pszRecv;
	delete[] recvBuf;
	m_strResult.TrimLeft(L" \r\n");  // trim junk from beginning
	m_strResult.TrimRight(L" \r\n"); // ...and end

	return S_OK;
}
Exemple #8
0
HRESULT CPigEngine::GetInvokeCommands(CPigBehaviorScriptType* pType,
  CPigEngine::XBehaviorMap& mapCommands)
{
  // Get the collection of invoke commands for the new object
  ITCStringsPtr spInvokeCommands;
  _SVERIFYE(pType->get_InvokeCommands(&spInvokeCommands));
  assert(NULL != spInvokeCommands);

  // Iterate through each one and add it to a local map, ignoring duplicates
  long cInvokeCommands = 0;
  _SVERIFYE(spInvokeCommands->get_Count(&cInvokeCommands));
  for (_variant_t i(0L); V_I4(&i) < cInvokeCommands; ++V_I4(&i))
  {
    CComBSTR bstrCommand;
    _SVERIFYE(spInvokeCommands->get_Item(&i, &bstrCommand));
    USES_CONVERSION;
    tstring strCommand(OLE2CT(bstrCommand));

    XBehaviorMapIt it = mapCommands.find(strCommand);
    if (mapCommands.end() == it)
      mapCommands.insert(std::make_pair(strCommand, pType));
  }
  return S_OK;
}
Exemple #9
0
BOOL CBibedtApp::OnDDECommand(LPTSTR lpszCommand)
{
	// Server: bibedt
	// Topic: System
	if (CWinApp::OnDDECommand(lpszCommand))
		return TRUE;

   // Handle any DDE commands recognized by your application
   // and return TRUE.  See implementation of CWinApp::OnDDEComand
   // for example of parsing the DDE command string.

	CString	strCommand(lpszCommand);
	CString	strFileName(lpszCommand);	

	CString	itemKey;
	CMainFrame* main = dynamic_cast<CMainFrame*>(AfxGetMainWnd());
	if (main == NULL)
		return FALSE;
	CBibedtDoc* doc = dynamic_cast<CBibedtDoc*>(main->GetActiveDocument());
	if (doc == NULL)
		return FALSE;
	int	nStart, nEnd;
	if (strCommand.Left(7).CompareNoCase(_T("[goto(\"")) == 0) {
		// handle goto command => [goto("filepath", "itemkey")]

		// get file name
		nStart = strCommand.Find(_T('"'));
		nEnd = strCommand.Find(_T('"'), nStart + 1);
		if (nStart == -1 || nEnd == -1 || nEnd - nStart <= 1)
			return FALSE;

		strFileName = strCommand.Mid(nStart + 1, nEnd - (nStart + 1));

		// get key
		nStart = strCommand.Find(_T('"'), nEnd + 1);
		nEnd = strCommand.Find(_T('"'), nStart + 1);
		if (nStart == -1 || nEnd == -1 || nEnd - nStart <= 1)
			return FALSE;

		itemKey = strCommand.Mid(nStart + 1, nEnd - (nStart + 1));

		// open the document
		OpenDocumentFile(strFileName);
		doc->SetSelected(itemKey);
		return TRUE;
	} else if (strCommand.Left(8).CompareNoCase(_T("[focus(\"")) == 0) {
		// [focus("key")]
		// get key
		nStart = strCommand.Find(_T('"'));
		nEnd = strCommand.Find(_T('"'), nStart + 1);
		if (nStart == -1 || nEnd == -1 || nEnd - nStart <= 1)
			return FALSE;
		itemKey = strCommand.Mid(nStart + 1, nEnd - (nStart + 1));
		doc->SetSelected(itemKey);
		return TRUE;
	} else if (strCommand.Left(7).CompareNoCase(_T("[find(\"")) == 0) {
		// [find("str")]
		nStart = strCommand.Find(_T('"'));
		nEnd = strCommand.Find(_T('"'), nStart + 1);
		if (nStart == -1 || nEnd == -1 || nEnd - nStart <= 1)
			return FALSE;
		itemKey = strCommand.Mid(nStart + 1, nEnd - (nStart + 1));
		main->SetQuicksearchText(itemKey);
		doc->DoQuickSearch(itemKey, main->GetQuicksearchFields(), TRUE);
		return TRUE;
	} else if (strCommand.Left(9).CompareNoCase(_T("[filter(\"")) == 0) {
		// [filter("name")]
		nStart = strCommand.Find(_T('"'));
		nEnd = strCommand.Find(_T('"'), nStart + 1);
		if (nStart == -1 || nEnd == -1 || nEnd - nStart <= 1)
			return FALSE;
		itemKey = strCommand.Mid(nStart + 1, nEnd - (nStart + 1));
		CBibItem* filter = doc->m_BibFile->Find(STR_FILTER);
		if (filter) {
			CField* flt = filter->Find(itemKey);
			if (flt) {
				main->SelectFilter(flt);
				doc->SetFilter(flt);
				return TRUE;
			}
		}
	}

   // Return FALSE for any DDE commands you do not handle.
   return FALSE;
}