コード例 #1
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;
   }
コード例 #2
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);
    }
}
コード例 #3
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;
	}
コード例 #4
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;
   }
コード例 #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
//********************************************************************************
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;
   }
コード例 #7
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
	}
コード例 #8
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;
	}
コード例 #9
0
//********************************************************************************
BOOL CRegValue::IterateEnumValue()
   {
   if(m_nEnum < 0)
      return FALSE;

   TCHAR sTemp[1024];
   DWORD nSize = sizeof(sTemp);

   SetOSResult(::RegEnumValue(GetKey(), m_nEnum, sTemp, &nSize,
      NULL, &m_nType, NULL, NULL));

   SetValueName(sTemp);

   m_nEnum += m_nEnumDirection;

   return GetOSResult() == ERROR_SUCCESS;
   }
コード例 #10
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;
	}
コード例 #11
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;
			}
		}
	}
コード例 #12
0
//********************************************************************************
BOOL CRegValue::DeleteValue()
   {
   SetOSResult(::RegDeleteValue(GetKey(), GetValueName()));

   return GetOSResult() == ERROR_SUCCESS;
   }
コード例 #13
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);
	}
コード例 #14
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;
	}
コード例 #15
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;
		}
	}