コード例 #1
0
ファイル: MapMgrApp.cpp プロジェクト: hkaiser/TRiAS
BOOL CMapMgrApp::InitInstance()
{
	if( !FirstInstance() )
		return FALSE;

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.


#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif


	SetDialogBkColor();        // Set dialog background color to gray
	LoadStdProfileSettings();  // Load standard INI file options (including MRU)
	AfxEnableControlContainer();

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CMapMgrDoc),
		RUNTIME_CLASS(CMainFrame),     // main SDI frame window
		RUNTIME_CLASS(CPictView));
	AddDocTemplate(pDocTemplate);

	// create a new (empty) document
	OnFileNew();
    ((CMainFrame*)GetMainWnd())->RestorePosition( SW_SHOWNORMAL );

	if (m_lpCmdLine[0] != '\0')
	{
		// TODO: add command line processing here
	}

	m_pMainWnd->SendMessage( WM_COMMAND, ID_APPSTART, 0 );
	return TRUE;
}
コード例 #2
0
BOOL CEventHandlerApp::InitInstance()
{
    // If app is already running, show it and bail out.
    if( !FirstInstance() ) {
		return false;
	}

    // ATL stuff added by MFC.
	if (!InitATL())
		return FALSE;


	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	SetRegistryKey(_T("QBSDK Tools"));


	if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
	{
		return TRUE;
	}


    CreateMainWindow();

    return TRUE;
}
コード例 #3
0
ファイル: instdata.c プロジェクト: mingpen/OpenNT
PPERF_INSTANCE FindInstanceN (PPERF_OBJECT pObject, DWORD N)
{
PPERF_INSTANCE pInst;
DWORD          i = 0;

    if (!pObject)
        return NULL;
    else if (N >= (DWORD)(pObject->NumInstances))
        return NULL;
    else
        {
        pInst = FirstInstance (pObject);

        while (i != N)
            {
            pInst = NextInstance (pInst);
            i++;
            }

        return pInst;
        }
}
コード例 #4
0
static AJ_Status GenXML(XMLWriterFunc XMLWriter, void* context, const AJ_Object* obj, const AJ_Object* objList)
{
    AJ_Status status;
    const AJ_Object* list = objList;

    /*
     * Ignore objects that are hidden or disabled
     */
    if (obj->flags & (AJ_OBJ_FLAG_HIDDEN | AJ_OBJ_FLAG_DISABLED)) {
        return AJ_OK;
    }
    XMLWriteTag(XMLWriter, context, nodeOpen, nameAttr, obj->path, 0, FALSE);
    if (SecurityApplies(NULL, obj, objList)) {
        XMLWriter(context, annotateSecure, 0);
        XMLWriter(context, secureTrue, 0);
    }
    status = ExpandInterfaces(XMLWriter, context, obj->interfaces);
    if (status == AJ_OK) {
        /*
         * Check if the object has any child nodes
         */
        while (list->path) {
            uint32_t len;
            const char* child = ChildPath(obj->path, list->path, &len);
            /*
             * If there is a child check that this is the first instance of this child.
             */
            if (child && (FirstInstance(obj->path, child, len, objList) == list)) {
                XMLWriteTag(XMLWriter, context, nodeOpen, nameAttr, child, len, TRUE);
            }
            ++list;
        }
        XMLWriter(context, nodeClose, sizeof(nodeClose));
    }
    return status;
}
コード例 #5
0
static void loadNetworkData(void)
{
  int32 i;
  unsigned int c;
  int32 val;
  char nausea[512];
  PPERF_COUNTER_DEFINITION PerfCntr;
  PPERF_COUNTER_DEFINITION CurCntr;
  PPERF_INSTANCE_DEFINITION PerfInst;
  PPERF_COUNTER_BLOCK PerfCntrBlk;

  if (NetworkObj == NULL) {
#ifdef FLG_DEBUG
    fprintf(stderr, "DEBUG: loadNetworkData, no NetworkObj!\n");
#endif
    return;
    }
  if (NetworkObj->NumInstances <= 0) {
#ifdef FLG_DEBUG
    fprintf(stderr, "DEBUG: loadNetworkData, NetworkObj->NumInstances <= 0!\n");
#endif
    return;
    }

  /* We're collecting sums, so start by zeroing out */
  netStats.loopbackPackets = 0;
  netStats.loopbackBytes = 0;
  netStats.packetsReceived = 0;
  netStats.bytesReceived = 0;
  netStats.packetsSent = 0;
  netStats.bytesSent = 0;


  PerfCntr = FirstCounter(NetworkObj);

  // retrieve all instances
  PerfInst = FirstInstance(NetworkObj);

  for (i = 0; i < NetworkObj->NumInstances; i ++) {
    boolean loopBack;

    wchar_t* unicodePtr = (wchar_t*)((PBYTE)PerfInst + PerfInst->NameOffset);
#if 0
    printf( "\n\tInstance %S: \n", unicodePtr);
#endif

    sprintf(nausea, "%S", unicodePtr);
    loopBack = strcmp(nausea, "MS TCP Loopback interface") == 0;

    PerfCntrBlk = (PPERF_COUNTER_BLOCK)((PBYTE)PerfInst + PerfInst->ByteLength);
    CurCntr = PerfCntr;

    // retrieve all counters
    for (c = 0; c < NetworkObj->NumCounters; c ++) {

#if 0
      printf("\t\tCounter %ld: %s\n",
         CurCntr->CounterNameTitleIndex,
         lpNamesArray[CurCntr->CounterNameTitleIndex]);
#endif

      switch (CurCntr->CounterNameTitleIndex) {
      case PACKETS_RECEIVED_ID:
        val = (int32)getLongValue(CurCntr, PerfCntrBlk);
        if (loopBack)
          netStats.loopbackPackets = val;
        else
          netStats.packetsReceived += val;
	break;
      case BYTES_RECEIVED_ID:
        val = (int32)getLongValue(CurCntr, PerfCntrBlk);
        if (loopBack)
          netStats.loopbackBytes = val;
        else
          netStats.bytesReceived += val;
	break;
      case PACKETS_SENT_ID:
        if (!loopBack) {
          val = (int32)getLongValue(CurCntr, PerfCntrBlk);
          netStats.packetsSent += val;
          }
	break;
      case BYTES_SENT_ID:
        if (!loopBack) {
          val = (int32)getLongValue(CurCntr, PerfCntrBlk);
          netStats.bytesSent += val;
          }
	break;
      default:
	/* unknown counter. just skip it. */
	break;
	}

      CurCntr = NextCounter(CurCntr);
      }
    PerfInst = NextInstance(PerfCntrBlk);
    }
}
コード例 #6
0
static void refreshProcess(jint pid, int32* intStorage, 
    int64* longStorage, double* doubleStorage)
{
#define INT_FIELD_STORE(field, value) \
    (intStorage[com_gemstone_gemfire_internal_WindowsProcessStats_##field##INT] = value)
#define LONG_FIELD_STORE(field, value) \
    (longStorage[com_gemstone_gemfire_internal_WindowsProcessStats_##field##LONG] = value)
#define DOUBLE_FIELD_STORE(field, value) \
    (doubleStorage[com_gemstone_gemfire_internal_WindowsProcessStats_##field##DOUBLE] = value)
#define FLOAT_FIELD_STORE(field, value) \
    DOUBLE_FIELD_STORE(field, (double)(value))

  int32 i;
  if (ProcessObj) {
    PPERF_INSTANCE_DEFINITION PerfInst;

    if (ProcessObj->NumInstances > 0) {
#if 0
      static int done = 0;
      if (!done) {
	done = 1;
	PerfInst = FirstInstance(ProcessObj);
	for (i=0; i < (int32)ProcessObj->NumInstances; i++) {
	  PPERF_COUNTER_BLOCK PerfCntrBlk;
	  PerfCntrBlk = (PPERF_COUNTER_BLOCK)((PBYTE)PerfInst + 
					      PerfInst->ByteLength);
	  printf("process: %s\n", getInstIdStr(PerfInst, "proc-"));
	  PerfInst = NextInstance(PerfCntrBlk);
	}
      }
#endif
      PerfInst = FirstInstance(ProcessObj);
      for (i=0; i < (int32)ProcessObj->NumInstances; i++) {
	PPERF_COUNTER_BLOCK PerfCntrBlk;
	PerfCntrBlk = (PPERF_COUNTER_BLOCK)((PBYTE)PerfInst + 
					    PerfInst->ByteLength);
	if (pid == getPid(pidCtrOffset, PerfCntrBlk)) {
          LONG_FIELD_STORE(activeTime, getLongValue(&processCtrCache[PROCESS_PROCESSORTIME_IDX], PerfCntrBlk));
          LONG_FIELD_STORE(userTime, getLongValue(&processCtrCache[PROCESS_USERTIME_IDX], PerfCntrBlk));
          LONG_FIELD_STORE(systemTime, getLongValue(&processCtrCache[PROCESS_PRIVILEGEDTIME_IDX], PerfCntrBlk));
          LONG_FIELD_STORE(virtualSizePeak, getLongValue(&processCtrCache[VIRTUALBYTESPEAK_IDX], PerfCntrBlk));
          LONG_FIELD_STORE(virtualSize, getLongValue(&processCtrCache[VIRTUALBYTES_IDX], PerfCntrBlk));

          LONG_FIELD_STORE(pageFaults, getLongValue(&processCtrCache[PAGEFAULTS_IDX], PerfCntrBlk));
          LONG_FIELD_STORE(workingSetSizePeak, getLongValue(&processCtrCache[WORKINGSETPEAK_IDX], PerfCntrBlk));
          LONG_FIELD_STORE(workingSetSize, getLongValue(&processCtrCache[WORKINGSET_IDX], PerfCntrBlk));
          LONG_FIELD_STORE(pageFileSizePeak, getLongValue(&processCtrCache[PAGEFILEBYTESPEAK_IDX], PerfCntrBlk));
          LONG_FIELD_STORE(pageFileSize, getLongValue(&processCtrCache[PAGEFILEBYTES_IDX], PerfCntrBlk));


          LONG_FIELD_STORE(privateSize, getLongValue(&processCtrCache[PRIVATEBYTES_IDX], PerfCntrBlk));
          INT_FIELD_STORE(threads, (int32)getLongValue(&processCtrCache[THREADCOUNT_IDX], PerfCntrBlk));
          INT_FIELD_STORE(priorityBase, (int32)getLongValue(&processCtrCache[PRIORITYBASE_IDX], PerfCntrBlk));
       /* ELAPSEDTIME omitted? */
       /* POOLPAGEDBYTES omitted? */

       /* POOLNONPAGEBYTES omitted? */
          INT_FIELD_STORE(handles, (int32)getLongValue(&processCtrCache[HANDLECOUNT_IDX], PerfCntrBlk));

          return;
	}
	PerfInst = NextInstance(PerfCntrBlk);
      }
    } else {
#ifdef FLG_DEBUG
      fprintf(stderr, "DEBUG: unexpected 0 instances!\n");
#endif
    }  
  }
#undef INT_FIELD_STORE
#undef LONG_FIELD_STORE
#undef FLOAT_FIELD_STORE
#undef DOUBLE_FIELD_STORE
}
コード例 #7
0
static void refreshSystem(int32* intStorage, int64* longStorage, double* doubleStorage)
{
#define INT_FIELD_STORE(field, value) \
    (intStorage[com_gemstone_gemfire_internal_WindowsSystemStats_##field##INT] = (int32)(value))
#define LONG_FIELD_STORE(field, value) \
    (longStorage[com_gemstone_gemfire_internal_WindowsSystemStats_##field##LONG] = (int64)(value))
#define DOUBLE_FIELD_STORE(field, value) \
    (doubleStorage[com_gemstone_gemfire_internal_WindowsSystemStats_##field##DOUBLE] = (double)(value))
#define FLOAT_FIELD_STORE(field, value) \
    DOUBLE_FIELD_STORE(field, (double)(value))

  {
    float usertime = 0.0;
    float systime = 0.0;
    float idletime = 0.0;
    float activetime = 0.0;
    float inttime = 0.0;
    if (lastFetchData.perfTimeMs != 0) {
      uint32 timeDelta = currentFetchData.perfTimeMs - lastFetchData.perfTimeMs;
      int64 valueDelta;
      valueDelta = currentFetchData.usertime - lastFetchData.usertime;
      usertime = (float)(100.0 * ((double)valueDelta / timeDelta));
      valueDelta = currentFetchData.systime - lastFetchData.systime;
      systime = (float)(100.0 * ((double)valueDelta / timeDelta));
      valueDelta = currentFetchData.inttime - lastFetchData.inttime;
      inttime = (float)(100.0 * ((double)valueDelta / timeDelta));
      valueDelta = currentFetchData.idletime - lastFetchData.idletime;
      idletime = (float)(100.0 * ((double)valueDelta / timeDelta));
      activetime = (float)(100.0 - idletime);
    }

    FLOAT_FIELD_STORE(cpuActive, activetime);
    FLOAT_FIELD_STORE(cpuUser, usertime);
    FLOAT_FIELD_STORE(cpuSystem, systime);
    FLOAT_FIELD_STORE(cpuInterrupt, inttime);
    FLOAT_FIELD_STORE(cpuIdle, idletime);
    INT_FIELD_STORE(interrupts, currentFetchData.interrupts);
  }

  if (SystemObj) {
    if (SystemObj->NumInstances == PERF_NO_INSTANCES) {
      PPERF_COUNTER_BLOCK PerfCntrBlk;
      PerfCntrBlk = (PPERF_COUNTER_BLOCK)FirstInstance(SystemObj);

      LONG_FIELD_STORE(contextSwitches, getLongValue(&systemCtrCache[TOTALCONTEXTSWITCHES_IDX], PerfCntrBlk));
      LONG_FIELD_STORE(systemCalls, getLongValue(&systemCtrCache[TOTALSYSTEMCALLS_IDX], PerfCntrBlk));
      INT_FIELD_STORE(processorQueueLength, getLongValue(&systemCtrCache[PROCESSORQUEUELENGTH_IDX], PerfCntrBlk));
      INT_FIELD_STORE(registryQuotaInUse, getLongValue(&systemCtrCache[REGISTRYQUOTAINUSE_IDX], PerfCntrBlk));


    } else {
#ifdef FLG_DEBUG
      fprintf(stderr, "DEBUG: unexpected >0 instances!\n");
#endif
    }
  }

  if (UdpObj) {
    if (UdpObj->NumInstances == PERF_NO_INSTANCES) {
      PPERF_COUNTER_BLOCK PerfCntrBlk;
      PerfCntrBlk = (PPERF_COUNTER_BLOCK)FirstInstance(UdpObj);

      INT_FIELD_STORE(dgramsReceived, getLongValue(&udpCtrCache[DATAGRAMS_RECEIVED_PER_SEC_IDX], PerfCntrBlk));
      INT_FIELD_STORE(dgramsNoPort, getLongValue(&udpCtrCache[DATAGRAMS_NO_PORT_PER_SEC_IDX], PerfCntrBlk));
      INT_FIELD_STORE(dgramsReceivedErrors, getLongValue(&udpCtrCache[DATAGRAMS_RECEIVED_ERRORS_IDX], PerfCntrBlk));
      INT_FIELD_STORE(dgramsSent, getLongValue(&udpCtrCache[DATAGRAMS_SENT_PER_SEC_IDX], PerfCntrBlk));
    } else {
#ifdef FLG_DEBUG
      fprintf(stderr, "DEBUG: unexpected >0 instances!\n");
#endif
    }
    
    }

  if (MemoryObj) {
    if (MemoryObj->NumInstances == PERF_NO_INSTANCES) {
      PPERF_COUNTER_BLOCK PerfCntrBlk;
      PerfCntrBlk = (PPERF_COUNTER_BLOCK)FirstInstance(MemoryObj);

      LONG_FIELD_STORE(availableMemory, getLongValue(&memoryCtrCache[AVAILABLEBYTES_IDX], PerfCntrBlk));
      LONG_FIELD_STORE(committedMemory, getLongValue(&memoryCtrCache[COMMITTEDBYTES_IDX], PerfCntrBlk));
      LONG_FIELD_STORE(committedMemoryLimit, getLongValue(&memoryCtrCache[COMMITLIMIT_IDX], PerfCntrBlk));
      LONG_FIELD_STORE(pageFaults, getLongValue(&memoryCtrCache[TOTALPAGEFAULTS_IDX], PerfCntrBlk));
      LONG_FIELD_STORE(cacheFaults, getLongValue(&memoryCtrCache[CACHEFAULTS_IDX], PerfCntrBlk));
      LONG_FIELD_STORE(demandZeroFaults, getLongValue(&memoryCtrCache[DEMANDZEROFAULTS_IDX], PerfCntrBlk));
      LONG_FIELD_STORE(pages, getLongValue(&memoryCtrCache[PAGES_IDX], PerfCntrBlk));
      LONG_FIELD_STORE(pagesInput, getLongValue(&memoryCtrCache[PAGESINPUT_IDX], PerfCntrBlk));
      LONG_FIELD_STORE(pageReads, getLongValue(&memoryCtrCache[PAGEREADS_IDX], PerfCntrBlk));
      LONG_FIELD_STORE(pagesOutput, getLongValue(&memoryCtrCache[PAGESOUTPUT_IDX], PerfCntrBlk));
      LONG_FIELD_STORE(pageWrites, getLongValue(&memoryCtrCache[PAGEWRITES_IDX], PerfCntrBlk));
      LONG_FIELD_STORE(cacheSize, getLongValue(&memoryCtrCache[CACHEBYTES_IDX], PerfCntrBlk));
      LONG_FIELD_STORE(cacheSizePeak, getLongValue(&memoryCtrCache[CACHEBYTESPEAK_IDX], PerfCntrBlk));
      INT_FIELD_STORE(committedMemoryInUse, getLongValue(&memoryCtrCache[COMMITTEDBYTESINUSE_IDX], PerfCntrBlk));
    } else {
#ifdef FLG_DEBUG
      fprintf(stderr, "DEBUG: unexpected >0 instances!\n");
#endif
    }
  }

  if (ObjectsObj) {
    if (ObjectsObj->NumInstances == PERF_NO_INSTANCES) {
      PPERF_COUNTER_BLOCK PerfCntrBlk;
      PerfCntrBlk = (PPERF_COUNTER_BLOCK)FirstInstance(ObjectsObj);

      INT_FIELD_STORE(processes, getLongValue(&objectsCtrCache[PROCESSES_IDX], PerfCntrBlk));
      INT_FIELD_STORE(threads, getLongValue(&objectsCtrCache[THREADS_IDX], PerfCntrBlk));
      INT_FIELD_STORE(events, getLongValue(&objectsCtrCache[EVENTS_IDX], PerfCntrBlk));
      INT_FIELD_STORE(semaphores, getLongValue(&objectsCtrCache[SEMAPHORES_IDX], PerfCntrBlk));
      INT_FIELD_STORE(mutexes, getLongValue(&objectsCtrCache[MUTEXES_IDX], PerfCntrBlk));
      INT_FIELD_STORE(sharedMemorySections, getLongValue(&objectsCtrCache[SECTIONS_IDX], PerfCntrBlk));
    } else {
#ifdef FLG_DEBUG
      fprintf(stderr, "DEBUG: unexpected >0 instances!\n");
#endif
    }
  }

  if (NetworkObj) {
    INT_FIELD_STORE(loopbackPackets, netStats.loopbackPackets);
    INT_FIELD_STORE(loopbackBytes, netStats.loopbackBytes);
    INT_FIELD_STORE(netPacketsReceived, netStats.packetsReceived);
    INT_FIELD_STORE(netBytesReceived, netStats.bytesReceived);
    INT_FIELD_STORE(netPacketsSent, netStats.packetsSent);
    INT_FIELD_STORE(netBytesSent, netStats.bytesSent);
    }
#undef INT_FIELD_STORE
#undef LONG_FIELD_STORE
#undef FLOAT_FIELD_STORE
#undef DOUBLE_FIELD_STORE
}
コード例 #8
0
ファイル: process.c プロジェクト: rn10950/RetroZilla
/******************************************************************************\
 * *       This is a part of the Microsoft Source Code Samples.
 * *       Copyright (C) 1993-1997 Microsoft Corporation.
 * *       All rights reserved.
\******************************************************************************/
BOOL _FindAndKillProcessNT4(LPSTR aProcessName, BOOL aKillProcess)
{
  BOOL          bRv;
  HKEY          hKey;
  DWORD         dwType;
  DWORD         dwSize;
  DWORD         dwTemp;
  DWORD         dwTitleLastIdx;
  DWORD         dwIndex;
  DWORD         dwLen;
  DWORD         pDataSize = 50 * 1024;
  LPSTR         szCounterValueName;
  LPSTR         szTitle;
  LPSTR         *szTitleSz;
  LPSTR         szTitleBuffer;
  PPERF_DATA    pData;
  PPERF_OBJECT  pProcessObject;

  bRv   = FALSE;
  hKey  = NULL;

  if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                  TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\perflib"),
                  0,
                  KEY_READ,
                  &hKey) != ERROR_SUCCESS)
    return(bRv);

  dwSize = sizeof(dwTitleLastIdx);
  if(RegQueryValueEx(hKey, TEXT("Last Counter"), 0, &dwType, (LPBYTE)&dwTitleLastIdx, &dwSize) != ERROR_SUCCESS)
  {
    RegCloseKey(hKey);
    return(bRv);
  }
    

  dwSize = sizeof(dwTemp);
  if(RegQueryValueEx(hKey, TEXT("Version"), 0, &dwType, (LPBYTE)&dwTemp, &dwSize) != ERROR_SUCCESS)
  {
    RegCloseKey(hKey);
    szCounterValueName = TEXT("Counters");
    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                    TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Perflib\\009"),
                    0,
                    KEY_READ,
                    &hKey) != ERROR_SUCCESS)
      return(bRv);
  }
  else
  {
    RegCloseKey(hKey);
    szCounterValueName = TEXT("Counter 009");
    hKey = HKEY_PERFORMANCE_DATA;
  }

  // Find out the size of the data.
  //
  dwSize = 0;
  if(RegQueryValueEx(hKey, szCounterValueName, 0, &dwType, 0, &dwSize) != ERROR_SUCCESS)
    return(bRv);


  // Allocate memory
  //
  szTitleBuffer = (LPTSTR)LocalAlloc(LMEM_FIXED, dwSize);
  if(!szTitleBuffer)
  {
    RegCloseKey(hKey);
    return(bRv);
  }

  szTitleSz = (LPTSTR *)LocalAlloc(LPTR, (dwTitleLastIdx + 1) * sizeof(LPTSTR));
  if(!szTitleSz)
  {
    if(szTitleBuffer != NULL)
    {
      LocalFree(szTitleBuffer);
      szTitleBuffer = NULL;
    }

    RegCloseKey(hKey);
    return(bRv);
  }

  // Query the data
  //
  if(RegQueryValueEx(hKey, szCounterValueName, 0, &dwType, (BYTE *)szTitleBuffer, &dwSize) != ERROR_SUCCESS)
  {
    RegCloseKey(hKey);
    if(szTitleSz)
      LocalFree(szTitleSz);
    if(szTitleBuffer)
      LocalFree(szTitleBuffer);

    return(bRv);
  }

  // Setup the TitleSz array of pointers to point to beginning of each title string.
  // TitleBuffer is type REG_MULTI_SZ.
  //
  szTitle = szTitleBuffer;
  while(dwLen = lstrlen(szTitle))
  {
    dwIndex = atoi(szTitle);
    szTitle = szTitle + dwLen + 1;

    if(dwIndex <= dwTitleLastIdx)
      szTitleSz[dwIndex] = szTitle;

    szTitle = szTitle + lstrlen(szTitle) + 1;
  }

  PX_PROCESS    = GetTitleIdx (NULL, szTitleSz, dwTitleLastIdx, PN_PROCESS);
  PX_PROCESS_ID = GetTitleIdx (NULL, szTitleSz, dwTitleLastIdx, PN_PROCESS_ID);
  PX_THREAD     = GetTitleIdx (NULL, szTitleSz, dwTitleLastIdx, PN_THREAD);
  wsprintf(INDEX_PROCTHRD_OBJ, TEXT("%ld %ld"), PX_PROCESS, PX_THREAD);
  pData = NULL;
  if(GetPerfData(HKEY_PERFORMANCE_DATA, INDEX_PROCTHRD_OBJ, &pData, &pDataSize) == ERROR_SUCCESS)
  {
    PPERF_INSTANCE pInst;
    DWORD          i = 0;

    pProcessObject = FindObject(pData, PX_PROCESS);
    if(pProcessObject)
    {
      LPSTR szPtrStr;
      int   iLen;
      char  szProcessNamePruned[MAX_BUF];
      char  szNewProcessName[MAX_BUF];

      if(sizeof(szProcessNamePruned) < (lstrlen(aProcessName) + 1))
      {
        if(hKey)
          RegCloseKey(hKey);
        if(szTitleSz)
          LocalFree(szTitleSz);
        if(szTitleBuffer)
          LocalFree(szTitleBuffer);

        return(bRv);
      }

      /* look for .exe and remove from end of string because the Process names
       * under NT are returned without the extension */
      lstrcpy(szProcessNamePruned, aProcessName);
      iLen = lstrlen(szProcessNamePruned);
      szPtrStr = &szProcessNamePruned[iLen - 4];
      if((lstrcmpi(szPtrStr, ".exe") == 0) || (lstrcmpi(szPtrStr, ".dll") == 0))
        *szPtrStr = '\0';

      pInst = FirstInstance(pProcessObject);
      for(i = 0; i < (DWORD)(pProcessObject->NumInstances); i++)
      {
        *szNewProcessName = '\0';
        if(WideCharToMultiByte(CP_ACP,
                               0,
                               (LPCWSTR)((PCHAR)pInst + pInst->NameOffset),
                               -1,
                               szNewProcessName,
                               MAX_BUF,
                               NULL,
                               NULL) != 0)
        {
          if(lstrcmpi(szNewProcessName, szProcessNamePruned) == 0)
          {
            if(aKillProcess)
              KillProcess(aProcessName, NULL, PX_PROCESS_ID);
            bRv = TRUE;
            break;
          }
        }

        pInst = NextInstance(pInst);
      }
    }
  }

  if(hKey)
    RegCloseKey(hKey);
  if(szTitleSz)
    LocalFree(szTitleSz);
  if(szTitleBuffer)
    LocalFree(szTitleBuffer);

  return(bRv);
}
コード例 #9
0
void GetProcessID(LPCTSTR pProcessName, std::vector<DWORD>& SetOfPID)
{
    PPERF_DATA_BLOCK pPerfData = NULL;
    PPERF_OBJECT_TYPE pPerfObj;
    PPERF_INSTANCE_DEFINITION pPerfInst;
    PPERF_COUNTER_DEFINITION pPerfCntr, pCurCntr;
    PPERF_COUNTER_BLOCK PtrToCntr;
    DWORD BufferSize = TOTALBYTES;
    DWORD i, j;
    LONG k;

    // Allocate the buffer for the performance data.

    pPerfData = (PPERF_DATA_BLOCK)malloc(BufferSize);

    wchar_t szKey[32];
    swprintf_s(szKey, L"%d %d", PROCESS_OBJECT_INDEX, PROC_ID_COUNTER);
    LONG lRes;
    while ((lRes = RegQueryValueEx(HKEY_PERFORMANCE_DATA,
                                   szKey,
                                   NULL,
                                   NULL,
                                   (LPBYTE)pPerfData,
                                   &BufferSize)) == ERROR_MORE_DATA)
    {
        // Get a buffer that is big enough.

        BufferSize += BYTEINCREMENT;
        pPerfData = (PPERF_DATA_BLOCK)realloc(pPerfData, BufferSize);
    }

    // Get the first object type.

    pPerfObj = FirstObject(pPerfData);

    // Process all objects.

    for (i = 0; i < pPerfData->NumObjectTypes; i++)
    {

        if (pPerfObj->ObjectNameTitleIndex != PROCESS_OBJECT_INDEX)
        {
            pPerfObj = NextObject(pPerfObj);
            continue;
        }

        SetOfPID.clear();

        // Get the first counter.

        pPerfCntr = FirstCounter(pPerfObj);

        // Get the first instance.

        pPerfInst = FirstInstance(pPerfObj);

        _bstr_t bstrProcessName, bstrInput;

        // Retrieve all instances.
        for (k = 0; k < pPerfObj->NumInstances; k++)
        {
            pCurCntr = pPerfCntr;
            bstrInput = pProcessName;
            bstrProcessName = (wchar_t *)((PBYTE)pPerfInst + pPerfInst->NameOffset);
            if (!_wcsicmp((LPCTSTR)bstrProcessName, (LPCTSTR)bstrInput))
            {
                // Retrieve all counters.

                for (j = 0; j < pPerfObj->NumCounters; j++)
                {
                    if (pCurCntr->CounterNameTitleIndex == PROC_ID_COUNTER)
                    {
                        PtrToCntr = CounterBlock(pPerfInst);
                        DWORD *pdwValue = (DWORD*)((LPBYTE)PtrToCntr + pCurCntr->CounterOffset);
                        SetOfPID.push_back(*pdwValue);
                        break;
                    }


                    // Get the next counter.

                    pCurCntr = NextCounter(pCurCntr);
                }
            }

            // Get the next instance.

            pPerfInst = NextInstance(pPerfInst);
        }
    }
    free(pPerfData);
    RegCloseKey(HKEY_PERFORMANCE_DATA);
}
コード例 #10
0
ファイル: CpDesktop.cpp プロジェクト: jimmccurdy/ArchiveGit
BOOL CCpDesktop::InitInstance()
{
	AfxOleInit();
	// we are a single instance app
    if (!FirstInstance())
        return(false);

	// InitCommonControls() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	InitCommonControls();

	CWinApp::InitInstance();

	// CG: The following block was added by the Splash Screen component.
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Register class factories via CoRegisterClassObject().
	if (FAILED(_AtlModule.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE)))
		return FALSE;
	// App was launched with /Embedding or /Automation switch.
	// Run app as automation server.
	if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
	{
		// Don't show the main window
		return TRUE;
	}
	// App was launched with /Unregserver or /Unregister switch.
	if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppUnregister)
	{
		_AtlModule.UpdateRegistryAppId(FALSE);
		_AtlModule.UnregisterServer(TRUE);
		return FALSE;
	}
	// App was launched with /Register or /Regserver switch.
	if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppRegister)
	{
		_AtlModule.UpdateRegistryAppId(TRUE);
		_AtlModule.RegisterServer(TRUE);
		return FALSE;
	}

	g_szAppName = "HP Design Studio";
	{
		char szModule[MAX_PATH];
		char szVersion[MAX_PATH];

		::GetModuleFileName(AfxGetInstanceHandle(), szModule, sizeof(szModule));
		CString strFilePath(szModule);
		GetFileVersion(strFilePath, szVersion);

		// if fileversion is less or equal to the registry just return 
		// else update the registry
		if (!RegistryUpToDate(REGVAL_HPAPP_VERSION, szVersion))
		{
			// register this version of the App
			CRegKey regkey;

			regkey.Open(REGKEY_APPROOT, REGKEY_APP);
			regkey.SetStringValue(REGVAL_HPAPP_VERSION, szVersion);
		}
	}

	CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);

	AfxEnableControlContainer();

	// Change the registry key under which our settings are stored
	SetRegistryKey(_T("American Greetings/CpApp"));

	CCpDialog dlg;
	m_pMainWnd = &dlg;
#ifndef _DEBUG
	CSplashWnd::ShowSplashScreen(GetSplashId(), NULL, 5000L);
#endif
	INT_PTR nResponse = dlg.DoModal();

	// Since the dialog has been closed, return false so that we exit the application,
	// rather than start the application's message pump.
	return false;
}
コード例 #11
0
ファイル: wildcard.c プロジェクト: mingpen/OpenNT
static
PDH_STATUS
PdhiExpandCounterPath (
    IN      LPCWSTR szWildCardPath,
    IN      LPVOID  pExpandedPathList,
    IN      LPDWORD pcchPathListLength,
    IN      BOOL    bUnicode
)
{
    PPERF_MACHINE       pMachine;
    PPDHI_COUNTER_PATH  pWildCounterPath = NULL;
    WCHAR               szWorkBuffer[MAX_PATH];
    WCHAR               szCounterName[MAX_PATH];
    WCHAR               szInstanceName[MAX_PATH];
    LPWSTR              szEndOfObjectString;
    LPWSTR              szInstanceString;
    LPWSTR              szCounterString;
    LPVOID              szNextUserString;
    PERF_OBJECT_TYPE    *pObjectDef;
    PERF_OBJECT_TYPE    *pParentObjectDef;
    PERF_COUNTER_DEFINITION *pCounterDef;
    PERF_INSTANCE_DEFINITION *pInstanceDef;
    PERF_INSTANCE_DEFINITION *pParentInstanceDef;

    DWORD               dwBufferRemaining;
    DWORD               dwSize;
    DWORD               dwSizeReturned = 0;
    PDH_STATUS          pdhStatus = ERROR_SUCCESS;

    DWORD               dwCtrNdx, dwInstNdx;
    BOOL                bMoreData = FALSE;

    // allocate buffers
    pWildCounterPath = G_ALLOC (GPTR, PDHI_COUNTER_PATH_BUFFER_SIZE);

    if (pWildCounterPath == NULL) {
      // unable to allocate memory so bail out
      pdhStatus = PDH_MEMORY_ALLOCATION_FAILURE;
    } else {
      __try {
        dwBufferRemaining = *pcchPathListLength;
        szNextUserString = pExpandedPathList;
      } __except (EXCEPTION_EXECUTE_HANDLER) {
        pdhStatus = PDH_INVALID_ARGUMENT;
      }
    }

    if (pdhStatus == ERROR_SUCCESS) {
      // Parse wild card Path 
                  
      dwSize = G_SIZE (pWildCounterPath);
      if (ParseFullPathNameW (szWildCardPath, &dwSize, pWildCounterPath)) {
        // get the machine referenced in the path
        pMachine = GetMachine (pWildCounterPath->szMachineName, 0);
        if (pMachine != NULL) {
          if (wcsncmp (cszDoubleBackSlash, szWildCardPath, 2) == 0) {
            // the caller wants the machine name in the path so
            // copy it to the work buffer
            lstrcpyW (szWorkBuffer, pWildCounterPath->szMachineName);
          } else {
            *szWorkBuffer = 0;
          }
          // append the object name (since wild card objects are not
          // currently supported.

          lstrcatW (szWorkBuffer, cszBackSlash);
          lstrcatW (szWorkBuffer, pWildCounterPath->szObjectName);
          szEndOfObjectString = &szWorkBuffer[lstrlenW(szWorkBuffer)];
          
          // get object pointer (since objects are not wild)
          pObjectDef = GetObjectDefByName (
            pMachine->pSystemPerfData,
            pMachine->dwLastPerfString,
            pMachine->szPerfStrings,
            pWildCounterPath->szObjectName);

          if (pObjectDef != NULL) {
            // for each counters and identify matches
            pCounterDef = FirstCounter (pObjectDef);
            for (dwCtrNdx = 0; dwCtrNdx < pObjectDef->NumCounters; dwCtrNdx++) {
              // for each counter check instances (if supported) 
              //  and keep matches
              if ((pCounterDef->CounterNameTitleIndex > 0) &&
                  (pCounterDef->CounterNameTitleIndex < pMachine->dwLastPerfString ) &&
                  (!((pCounterDef->CounterType & PERF_DISPLAY_NOSHOW) &&
                     // this is a hack because this type is not defined correctly
                    (pCounterDef->CounterType != PERF_AVERAGE_BULK)))) {
                // look up name of each object & store size
                lstrcpyW (szCounterName,
                  pMachine->szPerfStrings[pCounterDef->CounterNameTitleIndex]);
                if (WildStringMatchW(pWildCounterPath->szCounterName, szCounterName)) {
                  // if this object has instances, then walk down
                  // the instance list and save any matches
                  if (pObjectDef->NumInstances != PERF_NO_INSTANCES) {
                    // then walk instances to find matches
                    pInstanceDef = FirstInstance (pObjectDef);
                    if (pObjectDef->NumInstances > 0) {
                      for (dwInstNdx = 0;
                        dwInstNdx < (DWORD)pObjectDef->NumInstances;
                        dwInstNdx++) {
                        szInstanceString = szEndOfObjectString;
                        if (pInstanceDef->ParentObjectTitleIndex > 0) {
                          // then add in parent instance name
                          pParentObjectDef = GetObjectDefByTitleIndex (
                            pMachine->pSystemPerfData,
                            pInstanceDef->ParentObjectTitleIndex);
                          if (pParentObjectDef != NULL) {
                            pParentInstanceDef = GetInstance (
                              pParentObjectDef,
                              pInstanceDef->ParentObjectInstance);
                            if (pParentInstanceDef != NULL) {
                              GetInstanceNameStr (pParentInstanceDef,
                                szInstanceName,
                                pObjectDef->CodePage);
                              if (WildStringMatchW (pWildCounterPath->szParentName, szInstanceName)) {
                                // add this string
                                szInstanceString = szEndOfObjectString;
                                lstrcpyW (szInstanceString, cszLeftParen);
                                lstrcatW (szInstanceString, szInstanceName);
                                lstrcatW (szInstanceString, cszSlash);
                              } else {
                                // get next instance and continue 
                                pInstanceDef = NextInstance(pInstanceDef);
                                continue;
                              }
                            } else {
                              // unable to locate parent instance
                              // so cancel this one, then 
                              // get next instance and continue 
                              pInstanceDef = NextInstance(pInstanceDef);
                              continue;
                            }
                          } else {
                            // unable to locate parent object
                            // so cancel this one, then 
                            // get next instance and continue 
                            pInstanceDef = NextInstance(pInstanceDef);
                            continue;
                          }
                        } else {
                          // no parent name so continue
                          szInstanceString = szEndOfObjectString;
                          lstrcpyW (szInstanceString, cszSlash);
                        }
                        GetInstanceNameStr (pInstanceDef,
                          szInstanceName,
                          pObjectDef->CodePage);

                        //
                        //  BUGBUG: need to do something with indexes.
                        //
                        // if this instance name matches, then keep it
                        if (WildStringMatchW (pWildCounterPath->szInstanceName, szInstanceName)) {
                          lstrcatW (szInstanceString, szInstanceName);
                          lstrcatW (szInstanceString, cszRightParenBackSlash);
                          // now append this counter name
                          lstrcatW (szInstanceString, szCounterName);

                          // add it to the user's buffer if there's room
                          dwSize = lstrlenW(szWorkBuffer) + 1;
                          if (!bMoreData && (dwSize  < dwBufferRemaining)) {
                            if (bUnicode) {
                                lstrcpyW ((LPWSTR)szNextUserString, szWorkBuffer);
                                (LPBYTE)szNextUserString += dwSize * sizeof(WCHAR);
                            } else {
                                wcstombs ((LPSTR)szNextUserString, szWorkBuffer, dwSize);
                                (LPBYTE)szNextUserString += dwSize * sizeof(CHAR);
                            }
                            dwSizeReturned += dwSize;
                            dwBufferRemaining -= dwSize;
                          } else {
                            // they've run out of buffer so just update the size required
                            bMoreData = TRUE;
                            dwSizeReturned += dwSize;
                          }
                        } else {
                          // they don't want this instance so skip it
                        }
                        pInstanceDef = NextInstance (pInstanceDef);
                      } // end for each instance in object
                    } else {
                      // this object supports instances, 
                      // but doesn't currently have any
                      // so do nothing.
                    }
                  } else {
                    // this object does not use instances so copy this
                    // counter to the caller's buffer.
                    szCounterString = szEndOfObjectString;
                    lstrcpyW (szCounterString, cszBackSlash);
                    lstrcatW (szCounterString, szCounterName);
                    dwSize = lstrlenW(szWorkBuffer) + 1;
                    if (!bMoreData && (dwSize  < dwBufferRemaining)) {
                      if (bUnicode) {
                        lstrcpyW ((LPWSTR)szNextUserString, szWorkBuffer);
                        (LPBYTE)szNextUserString += dwSize * sizeof(WCHAR);
                      } else {
                        wcstombs ((LPSTR)szNextUserString, szWorkBuffer, dwSize);
                        (LPBYTE)szNextUserString += dwSize * sizeof(CHAR);
                      }
                      dwSizeReturned += dwSize;
                      dwBufferRemaining -= dwSize;
                    } else {
                      // they've run out of buffer so bail out of this loop
                      bMoreData = TRUE;
                      dwSizeReturned += dwSize;
                    }
                  }
                } else {
                  // this counter doesn't match so skip it
                }
              } else {
                // this counter string is not available
              }
              pCounterDef = NextCounter(pCounterDef);
            } // end for each counter in this object
            if (bUnicode) {
                *(LPWSTR)szNextUserString = 0;  // MSZ terminator
            } else {
                *(LPSTR)szNextUserString = 0;  // MSZ terminator
            }
            *pcchPathListLength = dwSizeReturned;
            if (bMoreData) {
              pdhStatus = PDH_MORE_DATA;
            } else {
              pdhStatus = ERROR_SUCCESS;
            }
          } else {
            // unable to find object
            pdhStatus = PDH_INVALID_PATH;
          }
        } else {
          // unable to connect to machine.
          pdhStatus = PDH_CANNOT_CONNECT_MACHINE;
        }
      } else {
        // unable to read input path string
          pdhStatus = PDH_INVALID_PATH;
      }
    }

    if (pWildCounterPath != NULL) G_FREE (pWildCounterPath);

    return pdhStatus;
}
コード例 #12
0
ファイル: X-FLR5.cpp プロジェクト: machinaut/xflr5
BOOL CXFLR5App::InitInstance()
{
	//protection for beta versions
	SYSTEMTIME time;
	GetSystemTime(&time);
//	if (time.wYear>=2009 || (time.wYear >=2008 && time.wMonth>=6)) 
//	{
//		AfxMessageBox("This version of XFLR5 has expired\nPlease download a new version", MB_OK);
//		return FALSE;
//	}
	// InitCommonControls() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
//	InitCommonControls();

	CWinApp::InitInstance();

	bTrace = false;
	if(bTrace)
	{
		CString strAppDirectory;
		char    szAppPath[MAX_PATH] = "";
		::GetModuleFileName(0, szAppPath, sizeof(szAppPath) - 1);
		// Extract directory
		strAppDirectory = szAppPath;
		strAppDirectory = strAppDirectory.Left(strAppDirectory.GetLength()-9);
		TraceFileName = strAppDirectory + "Trace.txt";
		CStdioFile tf;
		tf.Open(TraceFileName, CFile::modeCreate | CFile::modeWrite | CFile::typeText);
		tf.Close();
		Trace("CXFLR5App::Trace file open");

	}
	Trace("CX5App::InitInstance::Launching app");


//	AfxEnableControlContainer();

	//Trace("CX5App::InitInstance::Containers enabled");
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.
/*
#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif*/
	//Trace("CX5App::InitInstance::Controls Enabled");

	// Get command line info in case user has launched app from a file
	CCommandLineInfo CmdInfo;
	ParseCommandLine(CmdInfo);


	//Trace("CX5App::InitInstance::Command Line Info processed");

	if (!FirstInstance(CmdInfo))
	{
		//Trace("CX5App::InitInstance::Redirected input to first instance");
		//Trace("CX5App::InitInstance::Closing App");

		Trace("CXFLR5App::Not the first instance");
		return FALSE;
	}


	//Trace("CX5App::InitInstance::System time acquired");

	g_bBlackAndWhite = false;
	g_bColor         = true;
	g_bWindowBk      = false;
	g_bGraphBk       = false;
	m_PenWidth       = 10.0;

	// To create the main window, this code creates a new frame window
	// object and then sets it as the application's main window object.
	//Trace("CX5App::InitInstance::Global variables set");

	CMainFrame* pFrame = new CMainFrame;
	m_pMainWnd = pFrame;

	//Trace("CX5App::InitInstance::MainFrame created=", pFrame);
	//Trace("CX5App::InitInstance::ChildView created=", &(pFrame->m_wndView));

	CFile fp;
	int k,x,y,cx,cy,l,t,r,b;
	UINT showCmd;

	//load previously saved size and position

	CString str;
	CString strAppDirectory;
	char    szAppPath[MAX_PATH] = "";
	GetTempPath(MAX_PATH,szAppPath);
	strAppDirectory = szAppPath;
	str =strAppDirectory + "XFLR5.set";

	Trace("CXFLR5App::Default settings open");


	x=0; y=0; cx = GetSystemMetrics(SM_CXSCREEN); cy = GetSystemMetrics(SM_CYSCREEN);
	l=x; t = y;
	r = cx; b = cy;
	showCmd = SW_SHOWMAXIMIZED;

	try
	{
		if(fp.Open(str,CFile::modeRead))
		{
			CArchive ar(&fp, CArchive::load);
			ar >> k;
			if(k!=200416)
			{
				CArchiveException *pfe = new CArchiveException(CArchiveException::badIndex);
				pfe->m_strFileName = ar.m_strFileName;
				throw pfe;
			}
		//  we're reading/loading
			ar >> l >> t >> r >> b >> showCmd;
			x=l; y=t; cx = max(r-l,200); cy = max(b-t,200);
			ar.Close();
			fp.Close();
		} 
	}
	catch (CArchiveException *ex)
	{
		ex->Delete();
		fp.Close();
	}
	catch (CException *ex)
	{
		ex->Delete();
		fp.Close();
	}

	pFrame->m_wndpl.rcNormalPosition.left   = l;
	pFrame->m_wndpl.rcNormalPosition.right  = r;
	pFrame->m_wndpl.rcNormalPosition.top    = t;
	pFrame->m_wndpl.rcNormalPosition.bottom = b;
	pFrame->m_wndpl.showCmd = showCmd;

	// create and load the frame with its resources
	pFrame->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,	NULL);

	//set previously saved size and position
	pFrame->SetWindowPos(&CWnd::wndTop, x, y, cx, cy,SWP_NOREDRAW);
	pFrame->ShowWindow(showCmd);

	pFrame->UpdateWindow();

	if(!CmdInfo.m_strFileName.IsEmpty())
	{
		int app = pFrame->LoadFile(CmdInfo.m_strFileName, CmdInfo.m_strFileName);
		//Trace("CX5App::InitInstance::Loaded File " + CmdInfo.m_strFileName);

		if (app == MIAREX)			pFrame->OnMiarex();
		if (app == XFOILANALYSIS)	pFrame->OnXDirect();
	}
	
	return TRUE;
}