Example #1
1
HRESULT CCOMDispatchHelper::GetPropertyItemValues(const IDispatchPtr& pICollection, int iIndex, 
												  _bstr_t& bstrName, _bstr_t& bstrValue)
{
	HRESULT hr = E_FAIL;
	variant_t result, vIndex;
	vIndex.lVal = iIndex;
	vIndex.vt = VT_I4;
	hr = AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &result, pICollection, L"Item", 1, vIndex);
	RETURN_FAILED(hr);

	IDispatchPtr spPropItem = result.pdispVal;

	variant_t vPropItem;

	hr = AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &vPropItem, spPropItem, L"Name", 0);
	RETURN_FAILED(hr);

	bstrName.Assign(vPropItem.bstrVal);

	hr = AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &vPropItem, spPropItem, L"Value", 0);
	RETURN_FAILED(hr);

	//ComConvertUtils aComConvertUtils;

	//TODO look at a better way of casting a variant_t to a PROPVARIANT
	bstrValue = (LPCTSTR)PropVariantToString(*(PROPVARIANT*)(VARIANT*)&vPropItem);

	return hr;
}
HRESULT CAGCEventDef::ExpandParams(BSTR bstrFmt, IAGCEvent* pEvent,
  CAGCEventDef::XParamStrings& rParams)
{
  assert(BSTRLen(bstrFmt));

  // Initialize the parsing data
  XParseData data =
    {pEvent, NULL, &rParams, NULL, NULL, bstrFmt, NULL, false};

  // Iterate through the characters of the format string
  XStateProc pfnState = ParseState_Base;
  for (UINT cch = SysStringLen(bstrFmt); cch && pfnState; --cch)
  {
    RETURN_FAILED(pfnState(data));
    pfnState = data.m_pfnNextState;
    ++data.m_pszInput;
  }
  data.m_bEndOfString = true;
  while (pfnState)
  {
    RETURN_FAILED(pfnState(data));
    pfnState = data.m_pfnNextState;
  }

  // Indicate success
  return S_OK;
}
Example #3
0
HRESULT CPigEngine::get_AccountDispenser(IPigAccountDispenser** ppDispenser)
{
  // Get the computer name of the account server
  CComBSTR bstrServer;
  RETURN_FAILED(get_AccountServer(&bstrServer));
  if (!bstrServer.Length())
  {
    // Get the computer name of the mission server
    RETURN_FAILED(get_MissionServer(&bstrServer));
  }

  // Check for '.' to indicate this computer
  if (1 == bstrServer.Length() && OLESTR('.') == bstrServer[0])
    bstrServer.Empty();

  // Create the Pig Account Dispenser on the mission server
  COSERVERINFO si  = {0, bstrServer, NULL, 0};
  MULTI_QI     mqi = {&IID_IPigAccountDispenser, NULL, S_OK};
  RETURN_FAILED(CoCreateInstanceEx(CLSID_PigAccountDispenser, NULL,
    CLSCTX_SERVER, &si, 1, &mqi));

  // Copy the interface pointer to the [out] parameter
  ZSucceeded(mqi.hr);
  *ppDispenser = (IPigAccountDispenser*)mqi.pItf;

  // Indicate success
  return S_OK;
}
Example #4
0
HRESULT CPigEngine::CreatePig(BSTR bstrType, BSTR bstrCommandLine, IPig** ppPig)
{
  // Initialize the [out] parameter
  CLEAROUT(ppPig, (IPig*)NULL);

  // Lock the object for the following validation checks
  {
    XLock lock(this);

    // Ensure that the scripts have been loaded
    RETURN_FAILED(EnsureScriptsAreLoaded());

    // Ensure that the MissionServer property is not empty
    if (!m_bstrMissionServer.Length())
      return AtlReportError(CLSID_PigSession, IDS_E_NO_MISSIONSRV,
        IID_IPigSession, 0, _Module.GetResourceInstance());

    // Get the number of pigs that exist
    long cPigs = 0;
    if (m_pPigs)
      _SVERIFYE(m_pPigs->get_Count(&cPigs));

    // Get the maximum number of pigs allowed
    long nMaxPigs = 0;
    _SVERIFYE(get_MaxPigs(&nMaxPigs));

    // Check for maximum pigs
    if (nMaxPigs >= 0 && cPigs >= nMaxPigs)
      return AtlReportError(CLSID_PigSession, IDS_E_TOOMANYPIGS,
        IID_IPigSession, 0, _Module.GetResourceInstance());
  }

  // bstrType is optional, so assign a default value if not specified
  CComBSTR bstrTheType(bstrType);
  if (!bstrTheType.Length())
    bstrTheType = L"Default";

  // Find the specified behavior type
  CPigBehaviorScriptType* pBehaviorType = GetBehaviorType(bstrTheType);
  if (!pBehaviorType)
    return AtlReportError(CLSID_PigSession, IDS_E_CREATE_BEHAVIOR_TYPE,
      IID_IPigSession, 0, _Module.GetResourceInstance());

  // Create a new pig thread object and it's associated pig player object
  DWORD dwGITCookie;
  RETURN_FAILED(CPig::Create(pBehaviorType, bstrCommandLine, &dwGITCookie));

  // Get an apartment-safe pointer to the pig object
  RETURN_FAILED(GetInterfaceFromGlobal(dwGITCookie, IID_IPig, (void**)ppPig));
  assert(*ppPig);

  // Indicate success
  return S_OK;
}
HRESULT CAGCEventDef::ExpandFmtString(BSTR bstrFmt, IAGCEvent* pEvent,
  BSTR* pbstrOut)
{
  assert(BSTRLen(bstrFmt));
  assert(pbstrOut);

  // Create a growable stream into which we'll write
  IStreamPtr spStm;
  RETURN_FAILED(CreateStreamOnHGlobal(NULL, true, &spStm));

  // Initialize the parsing data
  XParseData data =
    {pEvent, spStm, NULL, NULL, NULL, bstrFmt, NULL, false};

  // Iterate through the characters of the format string
  XStateProc pfnState = ParseState_Base;
  for (UINT cch = SysStringLen(bstrFmt); cch && pfnState; --cch)
  {
    RETURN_FAILED(pfnState(data));
    pfnState = data.m_pfnNextState;
    ++data.m_pszInput;
  }
  data.m_bEndOfString = true;
  while (pfnState)
  {
    RETURN_FAILED(pfnState(data));
    pfnState = data.m_pfnNextState;
  }

  // Get the current seek pointer of the stream (which is it's size)
  LARGE_INTEGER li = {0};
  ULARGE_INTEGER uli;
  RETURN_FAILED(spStm->Seek(li, STREAM_SEEK_CUR, &uli));
  UINT cchStream = (UINT)uli.QuadPart / sizeof(OLECHAR);

  // Get the HGLOBAL underlying the stream
  HGLOBAL hGlobal = NULL;
  RETURN_FAILED(GetHGlobalFromStream(spStm, &hGlobal));
  assert(hGlobal);

  // Lock the HGLOBAL
  LPCOLESTR pszOut = reinterpret_cast<LPCOLESTR>(GlobalLock(hGlobal));
  assert(pszOut);

  // Create a BSTR from the byte stream
  *pbstrOut = SysAllocStringLen(pszOut, cchStream);

  // Unlock the HGLOBAL
  GlobalUnlock(hGlobal);

  // Indicate success or failure
  return *pbstrOut ? S_OK : E_OUTOFMEMORY;
}
HRESULT CPageEvents::GetElementID(IXMLDOMElement* pElem, int* pID)
{
  // Get the id or LowerBound attribute, in that order
  CComVariant var;
  if (FAILED(pElem->getAttribute(m_bstrID, &var)) ||
    FAILED(var.ChangeType(VT_I4)))
  {
    RETURN_FAILED(pElem->getAttribute(m_bstrLowerBound, &var));
    RETURN_FAILED(var.ChangeType(VT_I4));
  }
  *pID = V_I4(&var);
  return S_OK;
}
Example #7
0
STDAPI DllRegisterServer(void)
{
#ifdef _MERGE_PROXYSTUB
    RETURN_FAILED(PrxDllRegisterServer());
#endif

    // registers object, typelib and all interfaces in typelib
    RETURN_FAILED(_Module.RegisterServer(TRUE));

    // Register the component category
    return RegisterComponentCategory(CATID_TCObj,
                                     L"Allegiance Test Common Objects");
}
HRESULT CPageEvents::PopulateTreeAndList()
{
  // Get the XML text of the logger's current status
  CComBSTR bstrEventList;
  RETURN_FAILED(m_spEventLogger->get_EventList(&bstrEventList));

  // Load the XML text into the XMLDOM object
  VARIANT_BOOL bSucceeded;
  RETURN_FAILED(m_spXMLDoc->loadXML(bstrEventList, &bSucceeded));
  if (!bSucceeded)
    return E_FAIL;

  // Get the root element
  IXMLDOMElementPtr spRoot;
  RETURN_FAILED(m_spXMLDoc->get_documentElement(&spRoot));
  #ifdef _DEBUG
  {
    // Ensure that the root element tag is <AGCEvents>
    CComBSTR bstrRoot;
    ASSERT(SUCCEEDED(spRoot->get_tagName(&bstrRoot)));
    ASSERT(0 == wcscmp(bstrRoot, L"AGCEvents"));
  }
  #endif // _DEBUG

  // Recursively process the children of each group
  RETURN_FAILED(AddXMLNodeToTree(spRoot, TVI_ROOT));

  // Caculate the column widths
  m_cxMaxType += 16 + 2; // Adjust for icon and padding
  int cxScroll = GetSystemMetrics(SM_CXVSCROLL);

  // Get the width of the list control's client area
  CRect rect;
  m_listEvents.GetClientRect(rect);

  // Compute the Name column to fit the maximum width
  int cxTotal = m_cxMaxType + m_cxMaxID + cxScroll;
  int cxName = rect.Width() - cxTotal;

  // Set the column widths
  LVCOLUMN lvcol = {LVCF_WIDTH};
  lvcol.cx = m_cxMaxType;
  m_listEvents.SetColumn(0, &lvcol);
  lvcol.cx = m_cxMaxID;
  m_listEvents.SetColumn(1, &lvcol);
  lvcol.cx = cxName;
  m_listEvents.SetColumn(2, &lvcol);

  // Indicate success
  return S_OK;
}
/*-------------------------------------------------------------------------
 * get_GameParameters()
 *-------------------------------------------------------------------------
 */
STDMETHODIMP CAdminGame::get_GameParameters(IAGCGameParameters** ppParams) // overrides IAGCGameImpl
{
  // Perform default processing
  RETURN_FAILED(IAGCGameImplBase::get_GameParameters(ppParams));
  assert(*ppParams);

  // Get the IGC pointer
  ImissionIGC * pIGCMission = GetIGC();
  assert(pIGCMission);

  // Populate the team names
  for (SideLinkIGC*   psl = pIGCMission->GetSides()->first(); (psl != NULL); psl = psl->next())
  {
    IsideIGC*   pside = psl->data();

    if (pside)
    {
      CComBSTR bstrTemp(pside->GetName()); 
      RETURN_FAILED((*ppParams)->put_TeamName(pside->GetObjectID(), bstrTemp));
    }
  }

  // Get the CFSMission pointer
  CFSMission* pFSMission = GetHostIGC();

  // Set the StoryText property
  CComBSTR bstrStoryText(pFSMission->GetStoryText());
  RETURN_FAILED((*ppParams)->put_StoryText(bstrStoryText));

  // Set the starting tech bits
  if (pFSMission->m_pttbmAltered && pFSMission->m_pttbmNewSetting)
  {
    // Loop through the techbit masks for each team
    for (int iSide = 0; iSide < c_cSidesMax; ++iSide)
    {
      // Loop through each techbit
      for (short iBit = 0; iBit < c_ttbMax; ++iBit)
      {
        if (pFSMission->m_pttbmAltered[iSide].GetBit(iBit))
        {
          bool bBit = pFSMission->m_pttbmNewSetting[iSide].GetBit(iBit);
          (*ppParams)->put_OverriddenTechBit(iSide, iBit, VARBOOL(bBit));
        }
      }
    }
  }

  // Indicate success
  return S_OK;
}
Example #10
0
HRESULT TCUserAccount::HasRight(LPTSTR pszPrivilege) const
{
  // Not supported under Windows9x
  if (IsWin9x())
    return S_FALSE;

  // Fail if Init has not been called successfully
  if (!m_hPolicy || m_spSIDPrincipal.IsNull())
    return E_UNEXPECTED;

  // Fail if the specified pointer is NULL
  if (!pszPrivilege)
    return E_POINTER;

  // Get the array of user rights
  PLSA_UNICODE_STRING pUserRights = NULL;
  ULONG cRights = 0;
  RETURN_FAILED(LsaEnumerateAccountRights(m_hPolicy, m_spSIDPrincipal,
    &pUserRights, &cRights));

  // Get a pointer to a UNICODE version of the specified privilege
  USES_CONVERSION;
  LPCWSTR pszWidePrivilege = T2CW(pszPrivilege);

  // Loop through the array of privileges
  for (ULONG i = 0; i < cRights; ++i)
    if (0 == _wcsicmp(pUserRights[i].Buffer, pszWidePrivilege))
      return S_OK;

  // Specified privilege wasnt' found
  return S_FALSE;
}
Example #11
0
HRESULT TCUserAccount::RemoveRight(LPTSTR pszPrivilege)
{
  // Not supported under Windows9x
  if (IsWin9x())
    return S_FALSE;

  // Fail if Init has not been called successfully
  if (!m_hPolicy || m_spSIDPrincipal.IsNull())
    return E_UNEXPECTED;

  // Fail if the specified pointer is NULL
  if (!pszPrivilege)
    return E_POINTER;

  // Get a pointer to a UNICODE version of the specified privilege
  USES_CONVERSION;
  LPWSTR pszWidePrivilege = T2W(pszPrivilege);

  // Create an LSA_UNICODE_STRING for the specified privilege name
  LSA_UNICODE_STRING lsaString;
  lsaString.Length        = (USHORT)(wcslen(pszWidePrivilege) * sizeof(WCHAR));
  lsaString.MaximumLength = (USHORT)(lsaString.Length + sizeof(WCHAR));
  lsaString.Buffer        = pszWidePrivilege;

  // Attempt to remove the specified privilege from the current user
  RETURN_FAILED(LsaRemoveAccountRights(m_hPolicy, m_spSIDPrincipal, false,
    &lsaString, 1));

  // Indicate success
  return S_OK;
}
Example #12
0
HRESULT CPigShip::CreateCommandWrapper(Command cmd, IAGCCommand** ppCommand)
{
    // Initialize the [out] parameter
    CLEAROUT(ppCommand, (IAGCCommand*)NULL);

    // Create a new AGC.Command object
    IAGCCommandPrivatePtr spCmd;
    RETURN_FAILED(spCmd.CreateInstance(CLSID_AGCCommand));

    // Get the command target and id
    ImodelIGC* pModel = GetIGC()->GetCommandTarget(cmd);
    const CommandID idCmd = GetIGC()->GetCommandID(cmd);

    // Get the strings for the command target and id
    const char* pszTarget = pModel ? GetModelName(pModel) : NULL;
    const char* pszVerb = (0 <= idCmd && idCmd < c_cidMax) ?
                          c_cdAllCommands[idCmd].szVerb : "";

    // Initialize the new object
    spCmd->Init(pszTarget, pszVerb);

    // Query for the IAGCCommand interface
    _SVERIFYE(spCmd->QueryInterface(IID_IAGCCommand, (void**)ppCommand));

    // Indicate success
    return S_OK;
}
/*-------------------------------------------------------------------------
 * CAdminGame::get_GameOwnerUser()
 *-------------------------------------------------------------------------
 * Purpose:
 *   Returns the user that owns the game.   
 * 
 */
STDMETHODIMP CAdminGame::get_GameOwnerUser(/*[out, retval]*/ IAdminUser** ppUser)
{
  // Initialize the [out] parameter
  *ppUser = NULL;
  // CLEAROUT(ppUser, (IAdminUser*)NULL);

  ImissionIGC * pMission = GetIGC();

  if (!pMission || !(pMission->GetShips()) || pMission->GetShips()->n() == 0)
    return S_OK;

  CFSMission * pCFSMission = GetHostIGC();

  if (!pCFSMission)
    return S_OK;

  CFSPlayer* pfsPlayer = pCFSMission->GetOwner();

  if (!pfsPlayer)
    return S_OK;

  RETURN_FAILED(pfsPlayer->CAdminSponsor<CAdminUser>::Make(IID_IAdminUser, (void**)ppUser));

  // finish construction
  pfsPlayer->CAdminSponsor<CAdminUser>::GetLimb()->Init(pfsPlayer);

  return S_OK;
}
HRESULT CPageEvents::GetElementDisplayName(IXMLDOMElement* pElem, BSTR* pbstr)
{
  // Get the DisplayName or Name attribute, in that order
  CComVariant var;
  if (FAILED(pElem->getAttribute(m_bstrDisplayName, &var)) ||
    FAILED(var.ChangeType(VT_BSTR))            ||
    !V_BSTR(&var)                    ||
    !SysStringLen(V_BSTR(&var)))
  {
    RETURN_FAILED(pElem->getAttribute(m_bstrName, &var));
    RETURN_FAILED(var.ChangeType(VT_BSTR));
  }
  *pbstr = V_BSTR(&var);
  V_VT(&var) = VT_EMPTY;
  return S_OK;
}
STDMETHODIMP CTCPropBagOnRegKey::get_ObjectCLSID(BSTR* pbstrCLSID)
{
  try
  {
    // Initialize the [out] parameter
    CLEAROUT(pbstrCLSID, (BSTR)NULL);

    // Lock the object
    XLock lock(this);

    // Ensure that an internal property bag object has been created
    if (!m_pBag)
      return E_UNEXPECTED;

    // Forward the call to the internal property bag object
    CLSID clsid;
    RETURN_FAILED(m_pBag->GetObjectCLSID(_bstr_t(), clsid));

    // Convert the CLSID to a string
    *pbstrCLSID = BSTRFromGUID(clsid).copy();

    // Indicate success
    return S_OK;
  }
  TC_CATCH_ALL("CTCPropBagOnRegKey::get_ObjectCLSID()",
    RPC_E_SERVERFAULT)
}
Example #16
0
STDMETHODIMP TCUtilImpl::CreateObject(BSTR bstrProgID, BSTR bstrComputer,
  IUnknown** ppUnk)
{
  // Initialize the [out] parameter
  CLEAROUT(ppUnk, (IUnknown*)NULL);

  // Convert the specified ProgID to a CLSID
  CLSID clsid;
  if (!BSTRLen(bstrProgID))
    return E_INVALIDARG;
  RETURN_FAILED(CLSIDFromProgID(bstrProgID, &clsid));

  // Initialize the COSERVERINFO and MULTI_QI structures
  COSERVERINFO csi   = {0, bstrComputer, NULL, 0};
  MULTI_QI     mqi[] =
  {
    {&IID_IUnknown                 , NULL, S_OK},
    {&IID_IDispatch                , NULL, S_OK},
    {&IID_IConnectionPointContainer, NULL, S_OK},
  };
  const static ULONG cMQI = sizeofArray(mqi);

  // Determine if the specified computer name is definitely local
  bool bLocalForSure = true;
  if (BSTRLen(bstrComputer))
  {
    TCHAR szLocal[MAX_COMPUTERNAME_LENGTH + 1];
    DWORD cchLocal = sizeofArray(szLocal);
    GetComputerName(szLocal, &cchLocal);
    USES_CONVERSION;
    bLocalForSure = !_tcsicmp(szLocal, OLE2CT(bstrComputer));
  }
  DWORD dwClsCtx = bLocalForSure ? CLSCTX_SERVER : CLSCTX_REMOTE_SERVER;

  // Attempt to create the instance
  HRESULT hr = CoCreateInstanceEx(clsid, NULL, dwClsCtx, &csi, cMQI, mqi);
  if (FAILED(hr))
  {
    _TRACE_BEGIN
      _TRACE_PART1("TCCreateObject failed: hr=0x%08X", hr);
      _TRACE_PART1(", dwClsCtx=%hs", (CLSCTX_SERVER == dwClsCtx) ?
        "CLSCTX_SERVER" : "CLSCTX_REMOTE_SERVER");
      _TRACE_PART1(", ProgID=\"%ls\"", bstrProgID);
      _TRACE_PART1(", Computer= \"%ls\"\n", bstrComputer ?
        bstrComputer : L"");
    _TRACE_END
    return hr;
  }

  // Copy the IUnknown interface pointer to the [out] parameter
  *ppUnk = mqi[0].pItf;

  // Release each interface not being returned
  for (ULONG i = 1; i < cMQI; ++i)
    if (mqi[i].pItf)
      mqi[i].pItf->Release();

  // Return the result of the QI for IUnknown
  return mqi[0].hr;
}
HRESULT CServiceModule::InitAGC()
{
	// Initialize AGC
	HRESULT hr;
	ZSucceeded(hr = _AGCModule.Init());
	RETURN_FAILED(hr);

	_AGCModule.SetDebugBreakOnErrors(g.fWantInt3);

#ifdef _DEBUG
	_AGCModule.GetAGCGlobal()->SetDebugHook(&g_DebugHook);
#endif // _DEBUG

	// Create the set of available AGCEventID ranges
	CComPtr<IAGCEventIDRanges> spRanges;
	ZSucceeded(hr = spRanges.CoCreateInstance(L"AGC.EventIDRanges"));
	RETURN_FAILED(hr);

	// Add our ranges to it
	ZSucceeded(spRanges->AddByValues(EventID_AGC_LowerBound, EventID_AGC_UpperBound));
	ZSucceeded(spRanges->AddByValues(AllsrvEventID_Allsrv_LowerBound, AllsrvEventID_Allsrv_UpperBound));
	ZSucceeded(spRanges->AddByValues(EventID_Admin_LowerBound, EventID_Admin_UpperBound));

	// Set the ranges of available events
	GetAGCGlobal()->SetAvailableEventIDRanges(spRanges);

	// Create the event logger object
	ZSucceeded(hr = m_spEventLogger.CreateInstance("AGC.EventLogger"));
	RETURN_FAILED(hr);

	// Initialize the event logger object
	CComBSTR bstrEventSource(__MODULE__);
	CComBSTR bstrRegKey("HKLM\\" HKLM_FedSrvA);
	IAGCEventLoggerPrivatePtr spPrivate(m_spEventLogger);
	hr = spPrivate->Initialize(bstrEventSource, bstrRegKey);
	ZSucceeded(hr);
	RETURN_FAILED(hr);

	// Hook the event logger for DB event logging
	ZSucceeded(hr = spPrivate->put_HookForDBLogging(&g_DBLoggingHook));

	// Indicate success
	return S_OK;
}
Example #18
0
HRESULT CAGCEventDef::GetEventDescription(IAGCEvent* pEvent, BSTR* pbstrOut,
  const XEventDef* pDefHint)
{
  // Initialize the [out] parameter
  *pbstrOut = NULL;
  assert(pEvent);

  // Find the definition of the event ID, if not specified
  if (!pDefHint)
  {
    // Get the specified event's ID
    AGCEventID idEvent;
    RETURN_FAILED(pEvent->get_ID(&idEvent));

    // Lookup the event ID in the table
    const XEventDef* it = find(idEvent);
    if (end() == it)
      return E_INVALIDARG;
    pDefHint = it;
  }
  else
  {
    #ifdef _DEBUG
      // Get the specified event's ID
      AGCEventID idEvent;
      RETURN_FAILED(pEvent->get_ID(&idEvent));
      assert(pDefHint->m_id == idEvent);
    #endif // _DEBUG
  }

  // Get the event description formatting string
  CComBSTR bstrFmt;
  HRESULT hr = GetString(pDefHint->m_pszFormatDescription, &bstrFmt);
  RETURN_FAILED(hr);
  if (S_FALSE == hr)
  {
    // Use the static description
    return GetEventDescription(pDefHint->m_id, pbstrOut);
  }

  // Format the event
  assert(pEvent);
  return ExpandFmtString(bstrFmt, pEvent, pbstrOut);
}
Example #19
0
HRESULT CPigEngine::EnsureScriptsAreLoaded()
{
  // Return immediately if this initialization has already completed
  XLock lock(this);
  if (!m_hDirChange.IsNull() && m_pth)
    return S_OK;

  // Open the registry key of the AppID
  CRegKey key;
  RETURN_FAILED(_Module.OpenAppIDRegKey(key, KEY_READ));

  // Initialize the art path
  TCHAR szArtPath[_MAX_PATH];
  DWORD cch = sizeofArray(szArtPath);
  long lr = key.QueryValue(szArtPath, TEXT("ArtPath"), &cch);
  if (ERROR_SUCCESS != lr)
    return HRESULT_FROM_WIN32(lr);
  UTL::SetArtPath(szArtPath);

  // Convert the directory name to ANSI
  USES_CONVERSION;
  LPSTR pszScriptDir = OLE2A(m_bstrScriptDir);

  // Remove the whack at the end of the string
  cch = strlen(pszScriptDir);
  assert('\\' == pszScriptDir[cch - 1]);
  pszScriptDir[cch - 1] = '\0';

  // Ensure that the directory exists
  WIN32_FIND_DATA ffd;
  TCFileFindHandle hff = FindFirstFile(pszScriptDir, &ffd);
  if(hff.IsNull() || INVALID_HANDLE_VALUE == hff)
    return HRESULT_FROM_WIN32(GetLastError());

  // Initialize our record of the directory contents
  ProcessScriptDirChanges();

  // Create a directory change notification object
  const DWORD dwFilter = FILE_NOTIFY_CHANGE_FILE_NAME |
    FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_LAST_WRITE;
  m_hDirChange = FindFirstChangeNotification(pszScriptDir, false, dwFilter);
  if (INVALID_HANDLE_VALUE == m_hDirChange)
    return HRESULT_FROM_WIN32(GetLastError());

  // Create the thread that monitors the ProfileScriptDir folder
  m_pth = TCThread::BeginMsgThread(ScriptDirThunk, this,
    THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
  if (!m_pth)
    return E_FAIL;
  m_pth->ResumeThread();

  // TODO: Create the thread that monitors the CLSID registry key

  // Indicate success
  return S_OK;
}
/*-------------------------------------------------------------------------
 * CServiceModule::Init
 *-------------------------------------------------------------------------
 * Purpose:
 *    Init some COM/ATL/AGC stuff
 *
 */
HRESULT CServiceModule::Init(HINSTANCE hInst)
{
	// Initialize the ATL module
	HRESULT hr;
	ZSucceeded(hr = CComModule::Init(ObjectMap, hInst, &LIBID_ALLEGIANCESERVERLib));
	RETURN_FAILED(hr);

	// Indicate success
	return S_OK;
}
Example #21
0
//
// WriteToStream
//
// Override CPersistStream method.
// Write our properties to the stream.
//
HRESULT CCcFilter::WriteToStream(IStream *pStream)
{
	int iChannel = 0;
	AM_LINE21_CCSERVICE iService = AM_L21_CCSERVICE_None;
	ICcParser_CCTYPE iXformType = ICcParser_CCTYPE_None;

	VERIFY( SUCCEEDED( get_Channel( &iChannel )));
	VERIFY( SUCCEEDED( get_Service( &iService )));
	VERIFY( SUCCEEDED( get_XformType( &iXformType )));

	RETURN_FAILED( WriteInt(pStream, cDataInts));

	RETURN_FAILED( WriteInt(pStream, iChannel ));
	RETURN_FAILED( WriteInt(pStream, iService ));
	RETURN_FAILED( WriteInt(pStream, iXformType ));
	
	CPersistStream::SetDirty( FALSE );

	return NOERROR;
}
/*-------------------------------------------------------------------------
 * get_ProductVersion()
 *-------------------------------------------------------------------------
 * Purpose:
 *    Determine the version number of AllSrv
 *
 */
STDMETHODIMP CAdminSession::get_Version(IAGCVersionInfo** ppVersion)
{
	// Initialize the [out] parameter
	CLEAROUT(ppVersion, (IAGCVersionInfo*)NULL);

	// Create an instance of the version object
	IAGCVersionInfoPtr spVersion;
	RETURN_FAILED(spVersion.CreateInstance(CLSID_AGCVersionInfo));

	// Initialize the version object
	TCHAR szModule[_MAX_PATH];
	GetModuleFileName(_Module.GetModuleInstance(), szModule, sizeofArray(szModule));
	RETURN_FAILED(spVersion->put_FileName(CComBSTR(szModule)));

	// Detach the object to the [out] parameter
	*ppVersion = spVersion.Detach();

	// Indicate success
	return S_OK;
}
Example #23
0
HRESULT CPigShip::FinalConstruct()
{
    // Create a dummy event so that AutoAction always returns an object
    CComObject<CPigShipDummyEvent>* pDummyEvent = NULL;
    RETURN_FAILED(pDummyEvent->CreateInstance(&pDummyEvent));
    m_spDummyEvent = pDummyEvent;
    assert(NULL != m_spDummyEvent);

    // Indicate success
    return S_OK;
}
STDMETHODIMP CAdminSession::get_PerfCounters(IAGCEvent** ppPerfCounters)
{
	// Create an AGCEvent object to store the named performance counters
	IAGCEventCreatePtr spEvent;
	RETURN_FAILED(spEvent.CreateInstance(CLSID_AGCEvent));
	RETURN_FAILED(spEvent->Init());

	// Populate the event with the named performance counters
	CComVariant var(0L);
	V_I4(&var) = g.pServerCounters->cPacketsIn;
	RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"PacketsIn"), &var));

	V_I4(&var) = g.pServerCounters->cPlayersOnline;
	RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"PlayersOnline"), &var));

	V_I4(&var) = g.pServerCounters->timeBetweenInnerLoops;
	RETURN_FAILED(spEvent->AddProperty(CComBSTR(L"TimeInnerLoop"), &var));

	// Return the new object
	return spEvent->QueryInterface(IID_IAGCEvent, (void**)ppPerfCounters);
}
STDMETHODIMP CPigMissionParams::GetData(IStream** ppstm)
{
  // Initialize the [out] parameter
  CLEAROUT(ppstm, (IStream*)NULL);

  // Create a stream on global
  IStreamPtr spstm;
  RETURN_FAILED(CreateStreamOnHGlobal(NULL, true, &spstm));

  // Write the size of the data structure to the stream
  UINT cb = sizeof(m_mp);
  RETURN_FAILED(spstm->Write(&cb, sizeof(cb), NULL));

  // Write the data structure to the stream
  RETURN_FAILED(spstm->Write(&m_mp, cb, NULL));

  // Detach the interface to the [out] parameter
  *ppstm = spstm.Detach();

  // Indicate success
  return S_OK;
}
Example #26
0
HRESULT CPigEngine::put_MaxPigs(long nMaxPigs)
{
  // Open the registry key of the AppID
  CRegKey key;
  RETURN_FAILED(_Module.OpenAppIDRegKey(key));

  // Save the specified value
  long lr = key.SetValue((DWORD)nMaxPigs, TEXT("MaxPigs"));
  if (ERROR_SUCCESS != lr)
    return HRESULT_FROM_WIN32(lr);

  // Indicate success
  return S_OK;
}
Example #27
0
HRESULT CAGCEventDef::GetEventParameters (IAGCEvent* pEvent,
  CAGCEventDef::XParamStrings& rParamStrings, const XEventDef* pDefHint)
{
  assert(pEvent);

  // Find the definition of the event ID, if not specified
  if (!pDefHint)
  {
    // Get the specified event's ID
    AGCEventID idEvent;
    RETURN_FAILED(pEvent->get_ID(&idEvent));

    // Lookup the event ID in the table
    const XEventDef* it = find(idEvent);
    if (end() == it)
      return E_INVALIDARG;
    pDefHint = it;
  }
  else
  {
    #ifdef _DEBUG
      // Get the specified event's ID
      AGCEventID idEvent;
      RETURN_FAILED(pEvent->get_ID(&idEvent));
      assert(pDefHint->m_id == idEvent);
    #endif // _DEBUG
  }

  // Get the event description formatting string
  CComBSTR bstrFmt;
  HRESULT hr = GetString(pDefHint->m_pszFormatDescription, &bstrFmt);
  if (S_OK != hr)
    return hr;

  // Get the event parameters
  return ExpandParams(bstrFmt, pEvent, rParamStrings);
}
Example #28
-1
HRESULT CPigEngine::put_LobbyMode(PigLobbyMode eMode)
{
  // Get the number of pigs that exist
  XLock lock(this);
  long cPigs = 0;
  if (m_pPigs)
    RETURN_FAILED(m_pPigs->get_Count(&cPigs));

  // Fail if there are any pigs in existance
  if (cPigs)
    return AtlReportError(CLSID_PigSession, IDS_E_PROPUT_PIGSEXIST,
      IID_IPigSession, 0, _Module.GetResourceInstance());

  // Fail if an invalid mode is specified
  if (PigLobbyMode_Club > eMode || eMode > PigLobbyMode_Free)
    return AtlReportError(CLSID_PigSession, IDS_E_LOBBYMODE_UNSUPPORTED,
      IID_IPigSession, 0, _Module.GetResourceInstance());

  // Open the registry key of the AppID
  CRegKey key;
  RETURN_FAILED(_Module.OpenAppIDRegKey(key));

  // Save the specified lobby mode to the registry
  long lr = key.SetValue(static_cast<DWORD>(eMode), TEXT("LobbyMode"));
  if (ERROR_SUCCESS != lr)
    return HRESULT_FROM_WIN32(lr);

  // Save the specified lobby mode
  m_eLobbyMode = eMode;

  // Indicate success
  return S_OK;
}
Example #29
-1
HRESULT CPigEngine::put_AccountServer(BSTR bstrServer)
{
  // Get the number of pigs that exist
  XLock lock(this);
  long cPigs = 0;
  if (m_pPigs)
    RETURN_FAILED(m_pPigs->get_Count(&cPigs));

  // Fail if there are any pigs in existance
  if (cPigs)
    return AtlReportError(CLSID_PigSession, IDS_E_PROPUT_PIGSEXIST,
      IID_IPigSession, 0, _Module.GetResourceInstance());

  // Open the registry key of the AppID
  CRegKey key;
  RETURN_FAILED(_Module.OpenAppIDRegKey(key));

  // Save the specified value
  USES_CONVERSION;
  long lr = key.SetValue(BSTRLen(bstrServer) ? OLE2CT(bstrServer) : TEXT(""),
    TEXT("AccountServer"));
  if (ERROR_SUCCESS != lr)
    return HRESULT_FROM_WIN32(lr);

  // Save the string
  m_bstrAccountServer = bstrServer;

  // Indicate success
  return S_OK;
}
Example #30
-1
HRESULT TCUserAccount::SetRunAsInteractiveUser(LPCTSTR szAppID)
{
  // Not supported under Windows9x
  if (IsWin9x())
    return S_FALSE;

  // Copy the specified AppID string to a non-const wide string
  USES_CONVERSION;
  UINT cchAppID = max(_tcslen(szAppID), 48) + 1;
  LPWSTR pszAppID = (LPWSTR)_alloca(cchAppID * sizeof(WCHAR));
  wcscpy(pszAppID, T2CW(szAppID));

  // Resolve the specified string to an AppID
  HKEY hkey = NULL;
  RETURN_FAILED(ResolveAppID(pszAppID, &hkey));
  CRegKey key;
  key.Attach(hkey);

  // Set "Interactive User" as the RunAs user for the AppID
  // mdvalley: it used to be SetStringValue, but that ain't in my ATL.
  LONG lr = key.SetValue(TEXT("RunAs"), TEXT("Interactive User"));
  if (lr)
    return HRESULT_FROM_WIN32(lr);

  // Indicate success
  return S_OK;
}