HRESULT SIMPLEAPI OpenProfileStream(CProfileEntry* pEntry, IStream** pVal)
{
	if (!pEntry)
		return E_UNEXPECTED;

	CProfileFile* pFile=pEntry->GetOwningFile();
	if (pFile && pFile->CreateOrOpenStream(pEntry, false, NULL, pVal))
	{
		return pVal[0] ? S_OK : E_FAIL;
	}

	// Create an instance of ProfileStream object
	CProfileStream* pStream=new CRefCountedStream<CProfileStream>();
	CAutoPtr<IStream, SRefCounted> spStream(pStream);

	// Initialise it
	RETURNIFFAILED(pStream->Open(pEntry));
	
	*pVal=spStream.Detach();
	return S_OK;
} 
HRESULT SIMPLEAPI CreateProfileStream(CProfileEntry* pEntry, const wchar_t* pszSpec, IStream** pVal)
{
	if (!pEntry)
		return E_UNEXPECTED;

	if (!pszSpec)
		pszSpec=L"Streams\\Stream%.4i.bin";

	CProfileFile* pFile=pEntry->GetOwningFile();
	if (pFile && pFile->CreateOrOpenStream(pEntry, true, pszSpec, pVal))
	{
		return pVal[0] ? S_OK : E_FAIL;
	}

	// Create an instance of ProfileStream object
	CProfileStream* pStream=new CRefCountedStream<CProfileStream>();
	CAutoPtr<IStream, SRefCounted> spStream(pStream);

	// Initialise it
	RETURNIFFAILED(pStream->Create(pEntry));
	
	*pVal=spStream.Detach();
	return S_OK;
}
Exemple #3
0
int work()
{
  std::auto_ptr<ISocket> spSock(ISocket::create());
  if(!spSock.get())
  {
    ILog("Cannot create ISocket");
    return -39;
  }

  int nResult = spSock->connect("localhost", "27015");
  if(nResult)
  {
    ILogR("Error in listenAndAccept", nResult);
    return nResult;
  }
  ILog("> Connected to server");

  std::auto_ptr<ICertificate> spCert(ICertificate::create());
  if(!spCert.get())
  {
    ILog("Cannot create certificate");
    return -40;
  }
  ILog("> Certificate loaded");

  std::auto_ptr<ISecurityChannel> spSessionClient(
    ISecurityChannel::create());
  if(!spSessionClient.get())
  {
    ILog("Cannot create ISecurityChannel");
    return -41;
  }

  nResult = spSessionClient->authenticate(*spSock, *spCert);
  if(nResult)
  {
    ILogR("Error in authenticate", nResult);
    return nResult;
  }
  ILog("> Authentication complete");

  std::auto_ptr<ISecurityChannelStream> spStream(
    ISecurityChannelStream::create());
  if(!spStream.get())
  {
    ILog("Cannot create ISecurityChannelStream");
    return -42;
  }
  nResult = spStream->attach(*spSessionClient);
  if(nResult)
  {
    ILogR("Error in attach", nResult);
    return nResult;
  }

  std::string strMessage(">> Hello to Server!");
  nResult = spStream->send(strMessage.c_str(), strMessage.length() + 1);
  if(nResult)
  {
    ILogR("Error in send", nResult);
    return nResult;
  }
  ILog("Sent message: " + strMessage);

  char cBuffer[150] = "";
  size_t szRecieved = 0;
  nResult = spStream->receive(cBuffer, 150, szRecieved);
  if(nResult)
  {
    ILogR("Error in receive", nResult);
    return nResult;
  }

  ILog("Received message:");
  ILog(cBuffer);

  ILog("> Shutting down channel");
  nResult = spSessionClient->shutdown(true);
  if(nResult)
  {
    ILogR("Error in shutdown", nResult);
    return nResult;
  }
  return 0;
}