当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

 ·mywql和mssql的区别    »显示摘要«
    摘要: 如题,今晚内给分,说一点也给 ......
 ·并口打印问题解决,送分    »显示摘要«
    摘要: bytheway(到此一游) 接分! ......


●●● 帮忙看看这段程序,从注册表读取进程列表,大体解释一下就可以了,谢谢 ●●●

具体代码如下,大体解释一下原理就可以了,特别是那个lid是什么  
   
  void   FindProcessesW2K()  
  {  
          bool                                                 bErrorOccured=false;  
          DWORD                                                 rc;  
          HKEY                                                   hKeyNames;  
          DWORD                                                 dwType;  
          DWORD                                                 dwSize;  
          LPBYTE                                               buf   =   NULL;  
          TCHAR                                                 szSubKey[1024];  
          LANGID                                               lid;  
          LPSTR                                                 p;  
          LPSTR                                                 p2;  
          PPERF_DATA_BLOCK                           pPerf;  
          PPERF_OBJECT_TYPE                         pObj;  
          PPERF_INSTANCE_DEFINITION         pInst;  
          PPERF_COUNTER_BLOCK                     pCounter;  
          DWORD                                                 i;  
          TCHAR                                                   szProcessName[MAX_PATH];  
          DWORD                                                 dwLimit   =   256;  
          DWORD                                                 dwNumTasks;  
          lid   =   MAKELANGID(LANG_ENGLISH,   SUBLANG_NEUTRAL);  
          _stprintf(   szSubKey,   _T("%s\\%03x"),   REGKEY_PERF,   lid   );  
          rc   =   RegOpenKeyEx(   HKEY_LOCAL_MACHINE,  
                                                szSubKey,  
                                                0,  
                                                KEY_READ,  
                                                &hKeyNames  
                                            );  
          if   (rc   !=   ERROR_SUCCESS)  
  {  
  bErrorOccured=true;  
  m_strLastError=_T("Could   not   open   performance   registry   key");  
                  goto   exit;  
   
          }  
   
          //  
          //   get   the   buffer   size   for   the   counter   names  
          //  
          rc   =   RegQueryValueEx(hKeyNames,  
                                                      REGSUBKEY_COUNTERS,  
                                                      NULL,  
                                                      &dwType,  
                                                      NULL,  
                                                      &dwSize  
                                                  );  
   
          if   (rc   !=   ERROR_SUCCESS)  
  {  
  bErrorOccured=true;  
  m_strLastError=_T("Could   not   open   counter   registry   key");  
                  goto   exit;  
          }  
   
          //  
          //   allocate   the   counter   names   buffer  
          //  
          buf   =   (LPBYTE)   malloc(dwSize);  
          if   (buf   ==   NULL)  
  {  
  bErrorOccured=true;  
  m_strLastError=_T("Out   of   Memory");  
                  goto   exit;  
          }  
          memset(buf,   0,   dwSize);  
   
          //  
          //   read   the   counter   names   from   the   registry  
          //  
          rc   =   RegQueryValueEx(   hKeyNames,  
                                                      REGSUBKEY_COUNTERS,  
                                                      NULL,  
                                                      &dwType,  
                                                      buf,  
                                                      &dwSize  
                                                  );  
   
          if   (rc   !=   ERROR_SUCCESS)    
  {  
  bErrorOccured=true;  
  m_strLastError=_T("Could   Not   Read   the   counter   Names");  
                  goto   exit;  
          }  
   
          //  
          //   now   loop   thru   the   counter   names   looking   for   the   "Process"   counters:  
          //   the   buffer   contains   multiple   null   terminated   strings   and   then  
          //   finally   null   terminated   at   the   end.     the   strings   are   in   pairs   of  
          //   counter   number   and   counter   name.  
          //  
   
          p   =(LPSTR)   buf;  
          while   (*p)    
  {  
                  if   (p   >   (LPSTR)buf)    
  {  
                          for(   p2=p-2;   _istdigit(*p2);   p2--)  
  ;  
                  }  
                  if   (_tcsicmp(p,   PROCESS_COUNTER)   ==   0)  
  {  
                          //   look   backwards   for   the   counter   number  
                          for(p2=p-2;   _istdigit(*p2);   p2--)    
  ;  
                          _tcscpy(szSubKey,   p2+1);  
                  }  
                  p   +=   (_tcslen(p)   +   1);  
          }  
   
   
          //   free   the   counter   names   buffer  
          free(buf);  
   
   
          //   allocate   the   initial   buffer   for   the   performance   data  
   
          dwSize   =   INITIAL_SIZE;  
          buf   =   (LPBYTE)malloc(   dwSize   );  
          if   (buf   ==   NULL)  
  {  
  bErrorOccured=true;  
  m_strLastError=_T("Out   of   Memory");  
                  goto   exit;  
          }  
          memset(buf,   0,   dwSize);  
          while   (true)  
  {  
   
                  rc   =   RegQueryValueEx(   HKEY_PERFORMANCE_DATA,  
                                                              szSubKey,  
                                                              NULL,  
                                                              &dwType,  
                                                              buf,  
                                                              &dwSize  
                                                          );  
   
                  pPerf   =   (PPERF_DATA_BLOCK)   buf;  
   
                  //   check   for   success   and   valid   perf   data   block   signature  
   
                  if   ((rc   ==   ERROR_SUCCESS)   &&  
                          (dwSize   >   0)   &&  
                          (pPerf)->Signature[0]   ==   (WCHAR)P   &&  
                          (pPerf)->Signature[1]   ==   (WCHAR)E   &&  
                          (pPerf)->Signature[2]   ==   (WCHAR)R   &&  
                          (pPerf)->Signature[3]   ==   (WCHAR)F   )  
  {  
                          break;  
                  }  
   
                  //   if   buffer   is   not   big   enough,   reallocate   and   try   again  
   
                  if   (rc   ==   ERROR_MORE_DATA)  
  {  
                          dwSize   +=   EXTEND_SIZE;  
                          buf   =   (LPBYTE)realloc(   buf,   dwSize   );  
                          memset(   buf,   0,   dwSize   );  
                  }  
                  else    
  {  
  bErrorOccured=true;  
  m_strLastError=_T("Could   Not   Obtain   Performance   Data");  
  goto   exit;  
                  }  
          }  
   
          //   set   the   perf_object_type   pointer  
   
          pObj   =   (PPERF_OBJECT_TYPE)   ((DWORD)pPerf   +   pPerf->HeaderLength);  
          dwNumTasks   =   min(   dwLimit,   (DWORD)pObj->NumInstances   );  
          pInst   =   (PPERF_INSTANCE_DEFINITION)   ((DWORD)pObj   +   pObj->DefinitionLength);  
   
          //   loop   thru   the   performance   instance   data   extracting   each   process   name  
   
          for   (i=0;   i<dwNumTasks;   i++)  
  {  
                  //  
                  //   pointer   to   the   process   name  
                  //  
                  p   =   (LPSTR)   ((DWORD)pInst   +   pInst->NameOffset);  
   
                  //  
                  //   convert   it   to   ascii  
                  //  
                  rc   =   WideCharToMultiByte(   CP_ACP,  
                                                                      0,  
                                                                      (LPCWSTR)p,  
                                                                      -1,  
                                                                      szProcessName,  
                                                                      sizeof(szProcessName),  
                                                                      NULL,  
                                                                      NULL  
                                                                  );  
   
  if   (rc)  
  {  
  CString   temp=szProcessName;  
  if(temp!="svchost")  
  m_strArray.Add(szProcessName);  
  }  
                  //   get   the   process   id  
                  pCounter   =   (PPERF_COUNTER_BLOCK)   ((DWORD)pInst   +   pInst->ByteLength);  
                  //   next   process  
                  pInst   =   (PPERF_INSTANCE_DEFINITION)   ((DWORD)pCounter   +   pCounter->ByteLength);  
          }  
   
  exit:  
          if   (buf)    
  {  
                  free(buf);  
          }  
   
          RegCloseKey(hKeyNames);  
          RegCloseKey(HKEY_PERFORMANCE_DATA);  
  return   ;  
  }

NO.1   作者: cghao

use   CWnd   pWnd->AppName="";

NO.2   作者: xintiaf

进程列表里显示的是进程对应的文件名  
   
  应用程序列表里显示的是应用程序标题,标题没改,当然不会变  
  SetWindowText改一下  
 


    摘要: 为了说明问题, 我写了一段简单的代码表述: #include <iostream> using namespace std; class base { protected: virtual void func()=0; }; class test: virtual base { virtual void func() { cout << "tes......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE