text: #include "stdafx.h"
  #include "Utilities.h"
  #include <3FD\exceptions.h>
  #include <3FD\callstacktracer.h>
  #include <Poco\Data\ODBC\Connector.h>
  #include <cstdlib>
  #include <sstream>
  
  namespace application
  {
      using namespace _3fd;
      using namespace _3fd::core;
  
  
      static wchar_t localHostName[MAX_COMPUTERNAME_LENGTH + 1];
  
  
      /// <summary>
      /// Gets the name of localhost (not FQDN).
      /// </summary>
      /// <returns>The NetBIOS name of localhost.</returns>
      const wchar_t *GetLocalHostName()
      {
          static const wchar_t *ptr(nullptr);
          
          if (ptr != nullptr)
              return ptr;
  
          CALL_STACK_TRACE;
  
          DWORD lhnBufSize = (sizeof localHostName) / (sizeof localHostName[0]);
  
          if (GetComputerNameW(localHostName, &lhnBufSize) == FALSE)
          {
              std::ostringstream oss;
              oss << "Failed to get local host name! - ";
              WWAPI::AppendDWordErrorMessage(GetLastError(), "GetComputerName", oss);
              throw AppException<std::runtime_error>(oss.str());
          }
  
          return ptr = localHostName;
      }
  
  
      /// <summary>
      /// Initializes a new instance of the <see cref="OdbcClient"/> class.
      /// </summary>
      OdbcClient::OdbcClient()
      {
          Poco::Data::ODBC::Connector::registerConnector();
      }
  
  
      /// <summary>
      /// Generates a batch identifier for use in database operations.
      /// </summary>
      /// <returns>An ID which is unlikely to collide with
      /// another one generated by another thread or process.</returns>
      int16_t GenerateBatchId()
      {
          auto big = GetCurrentProcessId() + GetCurrentThreadId() + (time(nullptr) % 3600);
  
          auto a = static_cast<int> (big & 0xffff);
          auto b = static_cast<int> ((big >> 16) & 0xffff);
          auto c = static_cast<int> ((big >> 32) & 0xffff);
          auto d = static_cast<int> ((big >> 48) & 0xffff);
  
          return static_cast<int16_t> (rand() + (a ^ b ^ c ^ d));
      }
  
  }// end of namespace application
  