Пример #1
0
void CSetDBID::OnOK()
{
  UpdateData(TRUE);

  // Has user changed the index?
  if (m_iInitialDBIndex != m_iDBIndex) {
    // Has user disabled index feature?
    if (m_iDBIndex != 0) {
      // Try to get this index
      wchar_t szName[MAX_PATH];
      CreateUniqueName(UNIQUE_PWS_GUID, szName, MAX_PATH, SI_TRUSTEE_UNIQUE);

      CString csUserSBIndex;
      csUserSBIndex.Format(L"%s:DBI:%02d", static_cast<LPCWSTR>(szName), m_iDBIndex);

      m_hMutexDBIndex = CreateMutex(NULL, FALSE, csUserSBIndex);

      DWORD dwerr = ::GetLastError();
      if (dwerr == ERROR_ALREADY_EXISTS || dwerr == ERROR_ACCESS_DENIED) {
        CGeneralMsgBox gmb;
        gmb.AfxMessageBox(IDS_DBIDINUSE, MB_OK | MB_ICONEXCLAMATION);
        m_edtSBIndex.SetFocus();
        return;
      }
    }
  }

  CPWDialog::EndDialog(m_iDBIndex);
}
Пример #2
0
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Constructors / Destructors
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
CSingleInstance::CSingleInstance(const string& name)
{
	// Init vars
	char buffer[MAX_PATH];
	m_name = string(CreateUniqueName(name.c_str(), (char*)&buffer, SI_SESSION_UNIQUE));
	m_mmfilename = name + "_SingleInstance_MMF";
	m_isFirstInstance = false;

	m_hInstanceDataMutex = CreateMutex(NULL, false, "CSingleInstanceDataMutex");
	m_mutexWait = NULL;
	m_hExecuteLock = NULL;
}
// Returns TRUE, if there exists, according to the meaning of "unique" passed
// in nMode, another instance of this process.
BOOL IsInstancePresent( 
		LPCTSTR pszGUID, 
		int nMode	// = SI_DESKTOP_UNIQUE 
		)
{
	static HANDLE hMutex = NULL;
	
	if( hMutex == NULL ) {
		TCHAR szName[ MAX_PATH ];
		hMutex = CreateMutex( NULL, FALSE, CreateUniqueName( pszGUID, szName, nMode ) );
		return ( GetLastError() == ERROR_ALREADY_EXISTS || GetLastError() == ERROR_ACCESS_DENIED );
	}
	return FALSE;
}