コード例 #1
0
ファイル: regkeyinfo.cpp プロジェクト: richschonthal/HL7
//-------------------------------------------------------------------------------
CRegKeyInfo::CRegKeyInfo(const CRegKey& regkey)
{
    m_pClassName = NULL;
    if(! regkey.IsOpen())
    {
        SetResultCode(errKeyNotOpen);
        return;
    }
    DWORD nSize = 0;

    SetOSResult(::RegQueryInfoKey(regkey.GetKey(), NULL, &nSize,
                                  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL));

    if(GetOSResult() != ERROR_SUCCESS)
    {
        SetResultCode(errRegistry);
        return;
    }

    nSize += 1;
    m_pClassName = new TCHAR[nSize];
    SetOSResult(::RegQueryInfoKey(regkey.GetKey(), m_pClassName, &nSize, NULL,
                                  &m_nNumOfSubKeys, &m_nMaxSubKeyName, &m_nMaxClassName, &m_nNumOfValues,
                                  &m_nMaxValueName, &m_nMaxValueLen, &m_nSecurityDescLen, &m_ftLastWrite));

    if(GetOSResult() != ERROR_SUCCESS)
    {
        delete m_pClassName;
        m_pClassName = NULL;
        SetResultCode(errRegistry);
    }
}
コード例 #2
0
ファイル: Process.cpp プロジェクト: richschonthal/HL7
//--------------------------------------------------------------------------------
bool CProcess::Create(LPCTSTR pName, LPTSTR pCmdLine, LPCTSTR pCurDir,
		DWORD dwCreationFlags,
		bool bInheritHandles,
		LPSTARTUPINFO lpStartupInfo,
		LPSECURITY_ATTRIBUTES lpProcessAttributes,
		LPSECURITY_ATTRIBUTES lpThreadAttributes,
		LPVOID lpEnvironment)
	{
	STARTUPINFO si;
	if(lpStartupInfo == NULL)
		{
		::ZeroMemory((void*) &si, sizeof(si));
		si.cb = sizeof(si);
		lpStartupInfo = &si;
		}

	bool bRv = ::CreateProcess(pName, pCmdLine, lpProcessAttributes, lpThreadAttributes,
		(BOOL) bInheritHandles, dwCreationFlags, lpEnvironment, pCurDir,
		lpStartupInfo, &m_procInfo) != 0;

	if(! bRv)
		{
		SetResultCode(errOS);
		SetOSResult(::GetLastError());
		}

	return bRv;
	}
コード例 #3
0
//********************************************************************************
BOOL CRegValue::ReadValue(LPBYTE* pValue, const REGSAM samDesired)
   {
   DWORD nSize;
   DWORD nType;

   SetOSResult(::RegQueryValueEx(GetKey(), GetValueName(), 0, &nType, NULL, &nSize));

   if(GetOSResult() != ERROR_SUCCESS)
      return FALSE;

   if(GetValueType() > -1 && nType != GetValueType())
      {
      SetResultCode(errValueTypeMismatch);
      return FALSE;
      }

   *pValue = new BYTE[nSize];

   SetOSResult(::RegQueryValueEx(GetKey(), GetValueName(), 0, &m_nType, *pValue, &nSize));

   if(GetOSResult() != ERROR_SUCCESS)
      {
      delete *pValue;
      return FALSE;
      }
   return TRUE;
   }
コード例 #4
0
//--------------------------------------------------------------------------------
bool CPACSDatabase::Open()
	{
	ASSERT(m_nType != UNKNOWN);

	TRY
		{
		if(! m_db.OpenEx(m_sDBConnectString, CDatabase::noOdbcDialog|CDatabase::useCursorLib))
			{
			SetResultCode(errOS);
			return false;
			}
		}
	CATCH(CMemoryException, e)
		{
		CString sTemp;
		e->GetErrorMessage(sTemp.GetBuffer(1024), 1023);
		TRACE("open db memory error=%s", (LPCTSTR) sTemp);
		SetResultCode(errOS);
		return false;
		}
コード例 #5
0
//********************************************************************************
BOOL CRegValue::WriteValue(const LPBYTE pValue, DWORD nSize)
   {
   if(GetValueType() == -1)
      {
      SetResultCode(errUninitializedValueType);
      return FALSE;
      }

   SetOSResult(::RegSetValueEx(GetKey(), GetValueName(), 0, GetValueType(), (UCHAR*) pValue, nSize));

   return GetOSResult() == ERROR_SUCCESS;
   }
コード例 #6
0
ファイル: NamedPipeFile.cpp プロジェクト: richschonthal/HL7
//--------------------------------------------------------------------------------
void CNamedPipeFile::Write(const void* lpBuf, UINT nCount)
	{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	TRY
		{
		CFile::Write(lpBuf, nCount);
		}
	CATCH_ALL(e)
		{
		SetResultCode(CResult::errOS);
		SetOSResult(((CFileException*) e)->m_lOsError);
		}
	END_CATCH_ALL
	}
コード例 #7
0
ファイル: NamedPipeFile.cpp プロジェクト: richschonthal/HL7
//--------------------------------------------------------------------------------
UINT CLargeNamedPipeFile::Read(void* lpBuf, UINT nCount)
	{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	// and i quote (CFile) avoid win32 null read
	if(nCount == 0)
		return 0;

	// total msg size in bytes
	UINT nSize;

	ClearResult();

	if(CNamedPipeFile::Read(&nSize, sizeof(nSize)) != sizeof(nSize))
		return 0;

	if(HasErrors())
		return 0;

	if(nCount > 0 && nCount < nSize)
		{
		SetResultCode(CResult::errOS);
		SetOSResult(ERROR_INSUFFICIENT_BUFFER);
		return 0;
		}

	UINT nRemaining = nCount;
	UINT nRead = 0;
	UINT nTotal = 0;
	char* pBuf = (char*) lpBuf;

	UINT nPackets = (nSize / 65535) + 1;

	for(UINT i = 0; i < nPackets; i++)
		{
		nRead = CNamedPipeFile::Read(pBuf, nRemaining > 65535 ? 65535 : nRemaining);

	TRACE("read %d bytes\n", nRead);

		nRemaining -= nRead;
		nTotal += nRead;
		pBuf += nRead;
		if(HasErrors())
			break;
		}

	return nTotal;
	}
コード例 #8
0
ファイル: NamedPipeFile.cpp プロジェクト: richschonthal/HL7
//--------------------------------------------------------------------------------
UINT CNamedPipeFile::Read(void* lpBuf, UINT nCount)
	{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	UINT nBytes = 0;
	TRY
		{
		nBytes = CFile::Read(lpBuf, nCount);
		}
	CATCH_ALL(e)
		{
		SetResultCode(CResult::errOS);
		SetOSResult(((CFileException*) e)->m_lOsError);
		}
	END_CATCH_ALL

	return nBytes;
	}
コード例 #9
0
//********************************************************************************
BOOL CRegValue::ReadValue(LPDWORD pValue, REGSAM samDesired)
   {
   DWORD nSize;
   DWORD nType;

   SetOSResult(::RegQueryValueEx(GetKey(), GetValueName(), 0, &nType, NULL, &nSize));

   if(GetOSResult() != ERROR_SUCCESS)
      return FALSE;

   if(GetValueType() > -1 && nSize != sizeof(DWORD))
      {
      SetResultCode(errValueTypeMismatch);
      return FALSE;
      }

   SetOSResult(::RegQueryValueEx(GetKey(), GetValueName(), 0, &nType, (UCHAR*) pValue, &nSize));

   return GetOSResult() == ERROR_SUCCESS;
   }
コード例 #10
0
//--------------------------------------------------------------------------------
CExecuteApp::CExecuteApp(LPCTSTR pExe, LPCTSTR pParams, LPCTSTR pPath, DWORD nWaitTime)
		: m_hProcess(NULL)
		, m_nExitCode(0xffffffff)
	{
	SHELLEXECUTEINFO info;
	::ZeroMemory(&info, sizeof(SHELLEXECUTEINFO));
	info.cbSize = sizeof(SHELLEXECUTEINFO);
	info.fMask = SEE_MASK_FLAG_NO_UI|SEE_MASK_NOCLOSEPROCESS;
	info.lpFile = pExe;
	info.lpParameters = pParams;
	info.lpDirectory = pPath;
	info.nShow = SW_HIDE;

	SetResultCode(errOS);

	if(! ::ShellExecuteEx(&info))
		{
		SetOSResult(GetLastError());
		DebugPrintf(_T("ShellExecuteEx(%s,'%s','%s') error=%ld\n"), info.lpFile, pParams, pPath, GetOSResult());
		return;
		}

	m_hProcess = info.hProcess;

	if(nWaitTime != 0)
		{
		if(::WaitForSingleObject(m_hProcess, nWaitTime) != WAIT_OBJECT_0)
			{
			DebugPrintf(_T("wait on info.hProcess failed\n"));
			return;
			}

		BOOL bRunOk = ::GetExitCodeProcess(m_hProcess, &m_nExitCode);

		if(!bRunOk || m_nExitCode != 0)
			{
			DebugPrintf(_T("%s exits with %ld\n"), info.lpFile, m_nExitCode);
			return;
			}
		}
	}
コード例 #11
0
//********************************************************************************
BOOL CRegValue::ReadValue(CString& sValue, const REGSAM samDesired)
   {
   DWORD nSize;
   DWORD nType;

   SetOSResult(::RegQueryValueEx(GetKey(), GetValueName(), 0, &nType, NULL, &nSize));

   if(GetOSResult() != ERROR_SUCCESS)
      return FALSE;

   if(GetValueType() > -1 && nType != GetValueType())
      {
      SetResultCode(errValueTypeMismatch);
      return FALSE;
      }

   SetOSResult(::RegQueryValueEx(GetKey(), GetValueName(), 0, &m_nType,
      (UCHAR*) sValue.GetBuffer(nSize), &nSize));

   sValue.ReleaseBuffer();

   return GetOSResult() == ERROR_SUCCESS;
   }
コード例 #12
0
ファイル: Converter.cpp プロジェクト: Mariale13/UDS_Protocol
unsigned int CConverter::Convert(CString sCanoeFile)
{
    fstream fileInput,fileOutput;
    char acLine[defCON_MAX_LINE_LEN]; // I don't expect one line to be more than this
    fileInput.open(sCanoeFile, fstream::in);

    if(!fileInput.is_open())
    {
        return SetResultCode(CON_RC_FILEOPEN_ERROR_INFILE);
    }

    // first line of input file starts with keyword "VERSION", else file format error
    if(fileInput.getline(acLine, defCON_MAX_LINE_LEN) == NULL)
    {
        // eof file reached without reading anything
        fileInput.close();
        return SetResultCode(CON_RC_FORMAT_ERROR_INFILE);
    }
    else // if something was read
    {
        // verify the format
        if(strncmp(acLine, "VERSION ",8) != 0)
        {
            fileInput.close();
            return SetResultCode(CON_RC_FORMAT_ERROR_INFILE);
        }
    }

    // Generate the list of messages
    GenerateMessageList(fileInput);
    // All information gathered, validate and update if necessary
    // Make appropriate changes in the contents of the list
    ValidateMessageList();
    // the format is OK then open the output file
    //  bool bRes = WriteToOutputFile(fileOutput);
    fileInput.close();
    //  fileOutput.close();
    BOOL bRes = FALSE;

    if(!bRes)
    {
        CString sLogFile = sCanoeFile.Left(sCanoeFile.GetLength()-4);
        sLogFile += ".log";
        fstream fileLog;
        fileLog.open(sLogFile, fstream::out);

        if(!fileLog.is_open())
        {
            // if log file cannot be opened return the error code
            return SetResultCode(CON_RC_FILEOPEN_ERROR_LOGFILE);
        }
        else
        {
            CreateLogFile(fileLog);
            fileLog.close();
            return SetResultCode(CON_RC_COMPLETED_WITH_ERROR);
        }
    }

    return 1;
}
コード例 #13
0
ファイル: Converter.cpp プロジェクト: Mariale13/UDS_Protocol
bool CConverter::WriteToOutputFile(CString sCanMonFile)
{
    bool bResult = true;
    fstream fileOutput;
    // write to the output file
    // write header
    //  FILE *message = fopen("d:\\message.txt","w");
    fileOutput.open(sCanMonFile, fstream::out);

    if(!fileOutput.is_open())
    {
        // if output file cannot be opened the close the input file
        // and return the error code
        return SetResultCode(CON_RC_FILEOPEN_ERROR_OUTFILE);
    }

    fileOutput << CConverter::m_accHeader;
    fileOutput << endl;
    //Version no.
    fileOutput << defSTR_DB_VER " " defSTR_VER_NO;
    fileOutput << endl;
    fileOutput << endl;
    // number of messages
    fileOutput << "[NUMBER_OF_MESSAGES] " << m_listMessages.GetCount() << endl;
    fileOutput << endl;
    // write all messages, signals and value descriptors
    POSITION pos = m_listMessages.GetHeadPosition();

    while(pos != NULL)
    {
        CMessage& msg = m_listMessages.GetNext(pos);
        // MSG,MSGID,MSG_LENGTH,NO_OF_SIGNALS,DATA_FORMAT,FRAME_FORMAT
        fileOutput << "[START_MSG] " << msg.m_acName;
        fileOutput << "," << dec << msg.m_uiMsgID;
        fileOutput << "," << dec << msg.m_ucLength;
        fileOutput << "," << dec << msg.m_ucNumOfSignals;
        fileOutput << "," << msg.m_cDataFormat;
        fileOutput << "," << msg.m_cFrameFormat << endl;
        //      fprintf(message,"%s,%u,%u\n",msg.m_acName,msg.m_uiMsgID,msg.m_ucLength);
        POSITION posSig = msg.m_listSignals.GetHeadPosition();

        while(posSig != NULL)
        {
            // SIG_NAME,SIG_LENGTH,WHICH_BYTE_IN_MSG,START_BIT,SIG_TYPE,MAX_VAL,MIN_VAL,SIG_DATA_FORMAT,SIG_OFFSET,SIG_FACTOR,SIG_UNIT
            CSignal& sig = msg.m_listSignals.GetNext(posSig);

            // write signal only if it is valid
            if(sig.m_uiError == CSignal::SIG_EC_NO_ERR)
            {
                // For signal having motoroal format, the message length could be less
                // then eight byte. so in that case the whichByte needs to be shifted
                // accordingly.
                if(msg.m_cDataFormat == '0')
                {
                    sig.m_ucWhichByte = sig.m_ucWhichByte - (8 - msg.m_ucLength);
                }

                switch(sig.m_ucType)
                {
                    case CSignal::SIG_TYPE_BOOL:
                    case CSignal::SIG_TYPE_UINT:
                        fileOutput << "[START_SIGNALS] " << sig.m_acName;
                        fileOutput << "," << dec << sig.m_ucLength;
                        fileOutput << "," << dec << sig.m_ucWhichByte;
                        fileOutput << "," << dec << sig.m_ucStartBit;
                        fileOutput << "," << sig.m_ucType;
                        fileOutput << "," << dec << sig.m_MaxValue.uiValue;
                        fileOutput << "," << dec << sig.m_MinValue.uiValue;
                        fileOutput << "," << sig.m_ucDataFormat;
                        fileOutput << "," << sig.m_fOffset;
                        fileOutput << "," << sig.m_fScaleFactor;
                        fileOutput << "," << sig.m_acUnit;
                        fileOutput << "," << sig.m_acMultiplex;
                        fileOutput << "," << sig.m_rxNode << endl;
                        break;

                    case CSignal::SIG_TYPE_INT:
                        fileOutput << "[START_SIGNALS] " << sig.m_acName;
                        fileOutput << "," << dec << sig.m_ucLength;
                        fileOutput << "," << dec << sig.m_ucWhichByte;
                        fileOutput << "," << dec << sig.m_ucStartBit;
                        fileOutput << "," << sig.m_ucType;
                        fileOutput << "," << dec << sig.m_MaxValue.iValue;
                        fileOutput << "," << dec << sig.m_MinValue.iValue;
                        fileOutput << "," << sig.m_ucDataFormat;
                        fileOutput << "," << sig.m_fOffset;
                        fileOutput << "," << sig.m_fScaleFactor;
                        fileOutput << "," << sig.m_acUnit;
                        fileOutput << "," << sig.m_acMultiplex;
                        fileOutput << "," << sig.m_rxNode << endl;
                        break;

                        // Enable these when FLOAT and DOUBLE are supported
                        /*
                        case CSignal::SIG_TYPE_FLOAT:
                            sprintf(acLine,"[START_SIGNALS] %s,%u,%u,%u,%c,%f,%f,%c,%f,%f,%s\n",
                            sig.m_acName,sig.m_ucLength,sig.m_ucWhichByte,sig.m_ucStartBit,sig.m_ucType,
                            sig.m_MaxValue.fValue,sig.m_MinValue.fValue,sig.m_ucDataFormat,
                            sig.m_fOffset,sig.m_fScaleFactor,sig.m_acUnit);

                            break;

                        case CSignal::SIG_TYPE_DOUBLE:
                            sprintf(acLine,"[START_SIGNALS] %s,%u,%u,%u,%c,%f,%f,%c,%f,%f,%s\n",
                            sig.m_acName,sig.m_ucLength,sig.m_ucWhichByte,sig.m_ucStartBit,sig.m_ucType,
                            sig.m_MaxValue.dValue,sig.m_MinValue.dValue,sig.m_ucDataFormat,
                            sig.m_fOffset,sig.m_fScaleFactor,sig.m_acUnit);

                            break;
                        */

                    case CSignal::SIG_TYPE_INT64:
                        fileOutput << "[START_SIGNALS] " << sig.m_acName;
                        fileOutput << "," << dec << sig.m_ucLength;
                        fileOutput << "," << dec << sig.m_ucWhichByte;
                        fileOutput << "," << dec << sig.m_ucStartBit;
                        fileOutput << "," << 'I'; /* sig.m_ucType */
                        fileOutput << "," << dec << sig.m_MaxValue.dValue;
                        fileOutput << "," << dec << sig.m_MinValue.dValue;
                        fileOutput << "," << sig.m_ucDataFormat;
                        fileOutput << "," << sig.m_fOffset;
                        fileOutput << "," << sig.m_fScaleFactor;
                        fileOutput << "," << sig.m_acUnit;
                        fileOutput << "," << sig.m_acMultiplex;
                        fileOutput << "," << sig.m_rxNode << endl;
                        break;

                    case CSignal::SIG_TYPE_UINT64:
                        fileOutput << "[START_SIGNALS] " << sig.m_acName;
                        fileOutput << "," << dec << sig.m_ucLength;
                        fileOutput << "," << dec << sig.m_ucWhichByte;
                        fileOutput << "," << dec << sig.m_ucStartBit;
                        fileOutput << "," << 'U'; /* sig.m_ucType */
                        fileOutput << "," << dec << sig.m_MaxValue.dValue;
                        fileOutput << "," << dec << sig.m_MinValue.dValue;
                        fileOutput << "," << sig.m_ucDataFormat;
                        fileOutput << "," << sig.m_fOffset;
                        fileOutput << "," << sig.m_fScaleFactor;
                        fileOutput << "," << sig.m_acUnit;
                        fileOutput << "," << sig.m_acMultiplex;
                        fileOutput << "," << sig.m_rxNode << endl;
                        break;

                    default:
                        break;
                }

                // now write value descriptors for this signal
                POSITION posValDesc = sig.m_listValueDescriptor.GetHeadPosition();

                while(posValDesc != NULL)
                {
                    CValueDescriptor& rValDesc = sig.m_listValueDescriptor.GetNext(posValDesc);

                    switch(sig.m_ucType)
                    {
                        case CSignal::SIG_TYPE_BOOL:
                        case CSignal::SIG_TYPE_UINT:
                            fileOutput << "[VALUE_DESCRIPTION] " << rValDesc.m_acDescriptor;
                            fileOutput << "," << dec << rValDesc.m_value.uiValue << endl;
                            break;

                        case CSignal::SIG_TYPE_INT:
                            fileOutput << "[VALUE_DESCRIPTION] " << rValDesc.m_acDescriptor;
                            fileOutput << "," << dec << rValDesc.m_value.iValue << endl;
                            break;

                            // when FLOAT and DOUBLE are supported enable this
                            /*
                            case CSignal::SIG_TYPE_FLOAT:
                                sprintf(acLine,"[VALUE_DESCRIPTION] %s,%f\n",rValDesc.m_acDescriptor,rValDesc.m_value.fValue);
                                break;

                            case CSignal::SIG_TYPE_DOUBLE:
                                sprintf(acLine,"[VALUE_DESCRIPTION] %s,%f\n",rValDesc.m_acDescriptor,rValDesc.m_value.dValue);
                                break;
                            */

                        case CSignal::SIG_TYPE_INT64:
                            fileOutput << "[VALUE_DESCRIPTION] " << rValDesc.m_acDescriptor;
                            fileOutput << "," << dec << rValDesc.m_value.i64Value << endl;
                            break;

                        case CSignal::SIG_TYPE_UINT64:
                            fileOutput << "[VALUE_DESCRIPTION] " << rValDesc.m_acDescriptor;
                            fileOutput << "," << dec << rValDesc.m_value.ui64Value << endl;
                            break;

                        default:
                            break;
                    }
                }
            }
            else
            {
                bResult = false;
            }
        }

        //      fclose(message);
        fileOutput << "[END_MSG]" << endl << endl;
    }

    fileOutput.close();
    return bResult;
}
コード例 #14
0
ファイル: OutputConfig.cpp プロジェクト: richschonthal/HL7
//--------------------------------------------------------------------------------
COutputConfig::COutputConfig()
	{
	m_nRefCount++;

	if(m_pDBKeyName != NULL)
		return;

	CRegKey rkConfig(g_rkRoot, (LPCTSTR) NULL);

	if(! rkConfig.CreateKey())
		{
		SetResultCode(errOS);
		SetOSResult(::GetLastError());
		return;
		}

	CRegValueSz rvStr(rkConfig, REG_VALNAME_LOGFILE);
	CString sTemp;

	if(rvStr.ReadValue(sTemp))
		ALLOC_STRING(m_pLogFile, sTemp);

	rvStr.SetValueName(REG_OUTPUT_DBKEYNAME);

	if(rvStr.ReadValue(sTemp))
		ALLOC_STRING(m_pDBKeyName, sTemp);
	else
		ALLOC_STRING(m_pDBKeyName, "Database");

	CRegValueDWord rvVal(rkConfig, REG_VALNAME_TRACELEVEL_FLAGS);
	if(! rvVal.ReadValue(&m_nTraceLevel))
		m_nTraceLevel = m_nTraceLevelDefault;

	rvVal.SetValueName(REG_VALNAME_FLAGS);
	rvVal.ReadValue(&m_nFlags);

	rvStr.SetValueName(REG_OUTPUT_MONKEYNAME);
	if(rvStr.ReadValue(sTemp))
		ALLOC_STRING(m_pMonKeyName, sTemp);
	else
		ALLOC_STRING(m_pMonKeyName, "Monitors");

	// read the database config
	{
	CRegKey rkDB(rkConfig, m_pDBKeyName);
	if(! rkDB.OpenKey())
		return;
	CRegValueSz rvStr(rkDB, "");

	rvStr.SetValueName(REG_OUTPUT_VALNAME_DB_ODBC);
	if(rvStr.ReadValue(sTemp))
		ALLOC_STRING(m_pODBCString, sTemp);
	else
		ALLOC_STRING(m_pODBCString, "");

	rvStr.SetValueName(REG_OUTPUT_VALNAME_DB_TYPE);
	if(rvStr.ReadValue(sTemp))
		ALLOC_STRING(m_pDBType, sTemp);
	else
		ALLOC_STRING(m_pDBType, "");

	rvStr.SetValueName(REG_OUTPUT_VALNAME_DB_PROC);
	if(rvStr.ReadValue(sTemp))
		ALLOC_STRING(m_pProcAccnt, sTemp);
	else
		ALLOC_STRING(m_pProcAccnt, "");

	rvStr.SetValueName(REG_OUTPUT_VALNAME_DB_TABLE);
	if(rvStr.ReadValue(sTemp))
		ALLOC_STRING(m_pTableAccnt, sTemp);
	else
		ALLOC_STRING(m_pTableAccnt, "");

	}

	rvStr.SetValueName(REG_SECSERV_MAIN_IP);
	if(rvStr.ReadValue(sTemp))
		ALLOC_STRING(m_pSecServIP, sTemp);

	rvVal.SetValueName(REG_SECSERV_MAIN_PORT);
	rvVal.ReadValue(&m_nSecServPort);

	rvStr.SetValueName(REG_SECSERV_BKUP_IP);
	if(rvStr.ReadValue(sTemp))
		ALLOC_STRING(m_pSecServBkupIP, sTemp);

	rvVal.SetValueName(REG_SECSERV_BKUP_PORT);
	rvVal.ReadValue(&m_nSecServBkupPort);
	}
コード例 #15
0
ファイル: OutputConfig.cpp プロジェクト: richschonthal/HL7
//--------------------------------------------------------------------------------
bool COutputConfig::WriteConfig()
	{
	CRegKey rkConfig(g_rkRoot, (LPCTSTR) NULL);

	if(! rkConfig.OpenKey())
		{
		SetResultCode(errOS);
		SetOSResult(::GetLastError());
		return false;
		}

	CRegValueSz rvStr(rkConfig, REG_VALNAME_LOGFILE);
	CString sTemp;

	if(m_pLogFile != NULL)
		rvStr.WriteValue(m_pLogFile);

	rvStr.SetValueName(REG_OUTPUT_DBKEYNAME);

	if(m_pDBKeyName != NULL)
		rvStr.WriteValue(m_pDBKeyName);

	CRegValueDWord rvVal(rkConfig, REG_VALNAME_TRACELEVEL_FLAGS);
	rvVal.WriteValue(m_nTraceLevel);

	rvVal.SetValueName(REG_VALNAME_FLAGS);
	rvVal.WriteValue(m_nFlags);

	rvStr.SetValueName(REG_OUTPUT_MONKEYNAME);
	if(m_pMonKeyName != NULL)
		rvStr.WriteValue(m_pMonKeyName);

	// write the database config
	{
	CRegKey rkDB(rkConfig, m_pDBKeyName);
	if(! rkDB.CreateKey())
		return true;
	CRegValueSz rvStr(rkDB, "");

	rvStr.SetValueName(REG_OUTPUT_VALNAME_DB_ODBC);
	if(m_pODBCString != NULL)
		rvStr.WriteValue(m_pODBCString);

	rvStr.SetValueName(REG_OUTPUT_VALNAME_DB_TYPE);
	if(m_pDBType != NULL)
		rvStr.WriteValue(m_pDBType);

	rvStr.SetValueName(REG_OUTPUT_VALNAME_DB_PROC);
	if(m_pProcAccnt != NULL)
		rvStr.WriteValue(m_pProcAccnt);

	rvStr.SetValueName(REG_OUTPUT_VALNAME_DB_TABLE);
	if(m_pTableAccnt != NULL)
		rvStr.WriteValue(m_pTableAccnt);
	}

	rvStr.SetValueName(REG_SECSERV_MAIN_IP);
	if(m_pSecServIP != NULL)
		rvStr.WriteValue(m_pSecServIP);

	rvVal.SetValueName(REG_SECSERV_MAIN_PORT);
	rvVal.WriteValue(m_nSecServPort);

	rvStr.SetValueName(REG_SECSERV_BKUP_IP);
	if(m_pSecServBkupIP != NULL)
		rvStr.WriteValue(m_pSecServBkupIP);

	rvVal.SetValueName(REG_SECSERV_BKUP_PORT);
	rvVal.WriteValue(m_nSecServBkupPort);

	return true;
	}
コード例 #16
0
ファイル: NamedPipeFile.cpp プロジェクト: richschonthal/HL7
// Operations
//--------------------------------------------------------------------------------
BOOL CNamedPipeFile::Open(LPCTSTR lpszFileName, DWORD nOpenFlags, CFileException* pError)
	{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	// are we a server
	if(nOpenFlags & modeCreate)
		{
		// we've already created a pipe so
		// we just want to look for connections
		if(m_hFile != (UINT) INVALID_HANDLE_VALUE)
			{
			// if we've already made this call then
			// see if the event has signaled
			if(m_bConnectPending)
				{
				DWORD dwBytes;
				if(::GetOverlappedResult((HANDLE) m_hFile, &m_overlap, &dwBytes,
						((nOpenFlags&modeWaitForOpen)==modeWaitForOpen) ))
					{
					m_bConnectPending = false;
					m_evtComplete.ResetEvent();
					return true;
					}
				else
					{
					DWORD nErr = GetLastError();
					nErr = nErr;
					}

				return false;
				}
			else
				{
				m_overlap.hEvent = (HANDLE) m_evtComplete;
				m_bConnectPending = true;
				// got a connection right away?
				if(::ConnectNamedPipe((HANDLE) m_hFile, &m_overlap) != 0)
					{
					m_bConnectPending = false;
					return true;
					}
				else
					return false;
				}
			}

		DWORD nDirection;
 
		// look at the first 2 bits
		switch(nOpenFlags & 0x03)
			{
			case modeRead:
				nDirection = PIPE_ACCESS_INBOUND;
				break;
			case modeWrite:
				nDirection = PIPE_ACCESS_OUTBOUND;
				break;
			case modeReadWrite:
			default:
				nDirection = PIPE_ACCESS_DUPLEX;
				break;
			}

		DWORD nPipeType = (nOpenFlags & typeText) ? PIPE_TYPE_MESSAGE : PIPE_TYPE_BYTE;

		m_hFile = (UINT) ::CreateNamedPipe(
			lpszFileName,
			nDirection|FILE_FLAG_OVERLAPPED,
			nPipeType,
			PIPE_UNLIMITED_INSTANCES,
			1024,
			1024,
			10,
			NULL
			);

		return (HANDLE) m_hFile != INVALID_HANDLE_VALUE;
		}
	else
		// we are opening an exsisting pipe
		// so we are a client
		{
		CString sName(lpszFileName);
		BOOL b;
		for(int i = 0; i < 10; i++)
			if(b = ::WaitNamedPipe(sName, 1000))
				break;
		
		if(! b)
			{
			SetResultCode(CResult::errOS);
			SetOSResult(GetLastError());
			return false;
			}

		// we must be a client so open the pipe
		m_hFile = (UINT) ::CreateFile(
			(LPCTSTR) sName,		// pointer to name of the file
			GENERIC_WRITE|GENERIC_READ,			// access (read-write) mode
			FILE_SHARE_WRITE|FILE_SHARE_READ,		// share mode
			NULL,					// pointer to security attributes
			OPEN_EXISTING,			// how to create
			FILE_ATTRIBUTE_NORMAL,	// file attributes
			NULL
			);

		if((HANDLE) m_hFile == INVALID_HANDLE_VALUE)
			{
			SetResultCode(CResult::errOS);
			SetOSResult(GetLastError());
			return false;
			}
		else
			return true;
		}
	}