当前位置: 首页>>代码示例>>C++>>正文


C++ Thread32First函数代码示例

本文整理汇总了C++中Thread32First函数的典型用法代码示例。如果您正苦于以下问题:C++ Thread32First函数的具体用法?C++ Thread32First怎么用?C++ Thread32First使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Thread32First函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: write_thread_traces

static inline void write_thread_traces(struct exception_handler_data *data)
{
	THREADENTRY32 entry = {0};
	HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,
			GetCurrentProcessId());
	bool success;

	if (snapshot == INVALID_HANDLE_VALUE)
		return;

	entry.dwSize = sizeof(entry);

	success = !!Thread32First(snapshot, &entry);
	while (success) {
		write_thread_trace(data, &entry, true);
		success = !!Thread32Next(snapshot, &entry);
	}

	success = !!Thread32First(snapshot, &entry);
	while (success) {
		write_thread_trace(data, &entry, false);
		success = !!Thread32Next(snapshot, &entry);
	}

	CloseHandle(snapshot);
}
开发者ID:AnthonySuper,项目名称:obs-studio,代码行数:26,代码来源:obs-win-crash-handler.c

示例2: get_thread_ids

/**
 * Returns a std::vector<DWORD> of all thread IDs for a given process.
 *
 * If pid is 0 (the default) your current process ID is used.
 */
std::vector<unsigned long> get_thread_ids(unsigned long pid = 0)
{
	std::vector<DWORD> threadIds;
    THREADENTRY32 threadEntry;
    threadEntry.dwSize = sizeof(THREADENTRY32);

    // if not specified, default to THIS process
	if (!pid) pid = GetCurrentProcessId();

	// toolhelp: m$ft's most poorly named library?
    HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
    if(snapshot == INVALID_HANDLE_VALUE)
        return threadIds;

    if(!Thread32First(snapshot, &threadEntry)) {
        fprintf(stderr, "Thread32First: err code %d", GetLastError());
        CloseHandle(snapshot);
        return threadIds;
    }

    // find all threads matching pid
    do {
        if (threadEntry.th32OwnerProcessID == pid)
        	threadIds.push_back(threadEntry.th32ThreadID);
    } while(Thread32Next(snapshot, &threadEntry));

    CloseHandle(snapshot);
    return threadIds;
}
开发者ID:AlexUlrich,项目名称:digsby,代码行数:34,代码来源:debugapp.cpp

示例3: SetWindowText

void SeeThreadDlg::initThreadList()
{
	//遍历所有的thread;
	//
	SetWindowText(m_StrThread);
	THREADENTRY32 thd32={sizeof(THREADENTRY32)};
	HANDLE hThreadsnap;
	hThreadsnap=CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD
		,m_currPid);
	if (hThreadsnap==INVALID_HANDLE_VALUE)
	{
		return;
	}
	if (!Thread32First(hThreadsnap,&thd32))
	{
		CloseHandle(hThreadsnap);
		return;
	}
	m_VecThdList.clear();
	do 
	{
		_stprintf_s(strThreadId,_T("%d"),thd32.th32ThreadID);
		m_ThreadList.InsertItem(0,strThreadId);
		m_VecThdList.push_back(thd32);

	} while (Thread32Next(hThreadsnap,&thd32));
	CloseHandle(hThreadsnap);
}
开发者ID:stonedreamforest,项目名称:TaskManager,代码行数:28,代码来源:SeeThreadDlg.cpp

示例4: GetParentProcessInfo

// Obtain the process and thread identifiers of the parent process.
BOOL GetParentProcessInfo( LPPROCESS_INFORMATION ppi )
{
  HANDLE hSnap;
  PROCESSENTRY32 pe;
  THREADENTRY32  te;
  DWORD  id = GetCurrentProcessId();
  BOOL	 fOk;

  hSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS|TH32CS_SNAPTHREAD, id );

  if (hSnap == INVALID_HANDLE_VALUE)
    return FALSE;

  find_proc_id( hSnap, id, &pe );
  if (!find_proc_id( hSnap, pe.th32ParentProcessID, &pe ))
  {
    CloseHandle( hSnap );
    return FALSE;
  }

  te.dwSize = sizeof(te);
  for (fOk = Thread32First( hSnap, &te ); fOk; fOk = Thread32Next( hSnap, &te ))
    if (te.th32OwnerProcessID == pe.th32ProcessID)
      break;

  CloseHandle( hSnap );

  ppi->dwProcessId = pe.th32ProcessID;
  ppi->dwThreadId  = te.th32ThreadID;

  return fOk;
}
开发者ID:kmkkmk,项目名称:app,代码行数:33,代码来源:ansicon.c

示例5: GetMainThreadId

DWORD GetMainThreadId()
{
	DWORD dwCurProcessId = GetCurrentProcessId();
	HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, dwCurProcessId);
	if(hSnapshot == INVALID_HANDLE_VALUE)
	{
		return 0;
	}
	THREADENTRY32 te;
	te.dwSize=sizeof(THREADENTRY32);
	BOOL fOk=Thread32First(hSnapshot,&te);
	for(;fOk;){
		//the second parameter of CreateToolhelp32Snapshot will not work,so I have to enum
		//all Process
		if (te.th32OwnerProcessID == dwCurProcessId) 
		{
			//found process
			if (te.th32ThreadID!=0) 
			{
				return te.th32ThreadID;
			}
		}
		fOk=Thread32Next(hSnapshot,&te);
	}
	return 0;
}
开发者ID:kevinzhwl,项目名称:nxuiengine,代码行数:26,代码来源:Utility.cpp

示例6: GetProcessThreads

AIDLIB_API std::set<DWORD> GetProcessThreads(const DWORD processId)
{
TRY_CATCH
	std::set<DWORD> threads;
	CScopedTracker<HANDLE> threadSnap;

	// Retriving threads snapshot
	threadSnap.reset(CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, processId),CloseHandle);
	Log.Add(_MESSAGE_,_T("Retriving threads for process(%d), with handle(%d)"), processId, threadSnap.get());
	if (INVALID_HANDLE_VALUE == threadSnap)
		throw MCException_Win("Failed to CreateToolhelp32Snapshot");

	// Enumerating threads
	THREADENTRY32 threadEntry = {0};
	threadEntry.dwSize = sizeof(THREADENTRY32);
	if(Thread32First(threadSnap, &threadEntry))
	{
		do 
		{
			if (processId == threadEntry.th32OwnerProcessID)
				threads.insert(threadEntry.th32ThreadID);
			threadEntry.dwSize = sizeof(THREADENTRY32);
			threadEntry.th32ThreadID = 0;
		}
		while(Thread32Next(threadSnap, &threadEntry));
	} else
		throw MCException_Win("Failed to Thread32First");
	return threads;

CATCH_THROW()
}
开发者ID:uvbs,项目名称:SupportCenter,代码行数:31,代码来源:ThreadUtil.cpp

示例7: memset

vector<THREADENTRY32> CProcessTool::GetProcessThreads(DWORD dwOwnerPID)
{
	HANDLE hThreadSnap = INVALID_HANDLE_VALUE;
	THREADENTRY32 te32;
	VCTTHREAD vctThread;

	memset(&te32,0,sizeof(te32));
	hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,0);
	if(hThreadSnap == INVALID_HANDLE_VALUE)
		return vctThread;

	te32.dwSize = sizeof(THREADENTRY32);

	if(!Thread32First(hThreadSnap,&te32))
	{
		LOG::printError(TEXT("Thread32First"));
		CloseHandle(hThreadSnap);
		return vctThread;
	}


	do 
	{
		if(te32.th32OwnerProcessID == dwOwnerPID)
		{
			vctThread.push_back(te32);
		}
	} while (Thread32Next(hThreadSnap,&te32));

	CloseHandle(hThreadSnap);
	return vctThread;

}
开发者ID:louk78,项目名称:GetSystemInfo,代码行数:33,代码来源:processtool.cpp

示例8: resume_process

static BOOL
resume_process (DWORD dwOwnerPID)
{
  HANDLE        hThreadSnap = NULL;
  BOOL          bRet        = FALSE;
  THREADENTRY32 te32        = { 0 };

  hThreadSnap = CreateToolhelp32Snapshot (TH32CS_SNAPTHREAD, 0);
  if (hThreadSnap == INVALID_HANDLE_VALUE)
    return FALSE;

  te32.dwSize = sizeof (THREADENTRY32);

  if (Thread32First (hThreadSnap, &te32))
    {
      do
        {
          if (te32.th32OwnerProcessID == dwOwnerPID)
            {
              HANDLE hThread = OpenThread (THREAD_SUSPEND_RESUME, FALSE, te32.th32ThreadID);
              printf ("Resuming Thread: %u\n",te32.th32ThreadID);
              ResumeThread (hThread);
              CloseHandle (hThread);
            }
        }
      while (Thread32Next (hThreadSnap, &te32));
      bRet = TRUE;
    }
  else
    bRet = FALSE;

  CloseHandle (hThreadSnap);

  return bRet;
}
开发者ID:AdamGrzonkowski,项目名称:gimp-1,代码行数:35,代码来源:gimp-debug-resume.c

示例9: GetOneThreadID

short GetOneThreadID(short nPID)
{
	HANDLE hThreadSnap = NULL;
	THREADENTRY32 te32 = {0}; 

	hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
	if (hThreadSnap == INVALID_HANDLE_VALUE)
		return 0;

	memset(&te32, 0, sizeof(THREADENTRY32));
	te32.dwSize = sizeof(THREADENTRY32);

	if( Thread32First( hThreadSnap, &te32 ) )
	{
		do
		{
			if (te32.th32ThreadID && te32.th32OwnerProcessID == nPID)
			{
				CloseHandle (hThreadSnap);
				return te32.th32ThreadID;
			}

		} while ( Thread32Next( hThreadSnap, &te32 ) );
	}

	CloseHandle (hThreadSnap); 
	return 0;
}
开发者ID:WildeSE,项目名称:Source-Code,代码行数:28,代码来源:injection.cpp

示例10: enumerate_threads

	PDWORD enumerate_threads()
	{
		temp_var = 0;

		thread_entry = THREADENTRY32();
		snapshot	 = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, pid);
		
		if (snapshot != NULL)
		{
			thread_entry.dwSize = sizeof(thread_entry);
			success = Thread32First(snapshot, &thread_entry);

			while (success)
			{
				if (thread_entry.th32OwnerProcessID == pid)
				{
					thread_list[temp_var++] = thread_entry.th32ThreadID;
				}

				success = Thread32Next(snapshot, &thread_entry);
			}

			thread_list[temp_var] = ENT_OF_THREAD_LIST; // end of the thread_list
			CloseHandle(snapshot);
			return thread_list;
		}
		else
		{
			std::cout << "[!] enumerate_threads() error" << std::endl;
			return false;
		}
	}
开发者ID:err0rless,项目名称:debugger_,代码行数:32,代码来源:Debugger.cpp

示例11: GetNextThread

/*
 * GetNextThread -
 * NB - callers must continue to call this function until it returns FALSE
 */
BOOL GetNextThread( ThreadList *info, ThreadPlace *place,
                    DWORD pid, BOOL first )
{
    BOOL                        noerror;

    noerror = FALSE;
    if( first ) {
        place->thrddata = MemAlloc( sizeof( THREADENTRY32 ) );
        memset( place->thrddata, 0, sizeof( THREADENTRY32 ) );
        place->thrddata->dwSize =  sizeof( THREADENTRY32 );
        place->hdl = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
        noerror = Thread32First( place->hdl, place->thrddata );
        if( noerror ) {
            place->pid = pid;
        }
    } else {
        noerror = Thread32Next( place->hdl, place->thrddata );
    }
    while( noerror ) {
        if( pid == place->thrddata->th32OwnerProcessID ) break;
        noerror = Thread32Next( place->hdl, place->thrddata );
    }
    if( noerror ) {
        info->tid = place->thrddata->th32ThreadID;
        info->priority = place->thrddata->tpBasePri
                         + place->thrddata->tpDeltaPri;
    }
    if( !noerror ) {
        CloseHandle( place->hdl );
        MemFree( place->thrddata );
    }
    return( noerror );
}
开发者ID:ABratovic,项目名称:open-watcom-v2,代码行数:37,代码来源:reg95.c

示例12: CreateToolhelp32Snapshot

//-----------------------------------------------------------------------------
// 初始化
bool C_ThreadList::Initialize(IN unsigned long ulProcessID)
{
	m_Thread.clear();

	C_WHandle ccSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); // 取得處理程序中執行緒的快照

	if(ccSnap == INVALID_HANDLE_VALUE)
		return C_NOutput::Instance().Error(ERRORNSTD, C_ErrorWin(), __T("CreateToolhelp32Snapshot failed"));

	THREADENTRY32 sThread;

	ZeroMemory(&sThread, sizeof(sThread));
	sThread.dwSize = sizeof(sThread);

	// 取得第一個執行緒列表資訊
	if(Thread32First(static_cast<HANDLE>(ccSnap), &sThread) == FALSE)
		return C_NOutput::Instance().Error(ERRORNSTD, C_ErrorWin(), __T("Thread32First failed"));

	// 依序取得執行緒列表資訊
	do
	{
		// 檢查此執行緒資訊是否屬於輸入的處理程序
		if(sThread.th32OwnerProcessID == ulProcessID)
			m_Thread.push_back(S_Thread(sThread));
	} while(Thread32Next(static_cast<HANDLE>(ccSnap), &sThread) == TRUE);

	return true;
}
开发者ID:yinweli,项目名称:platform,代码行数:30,代码来源:threadlist.cpp

示例13: CreateToolhelp32Snapshot

/// <summary>
/// Gets all process threads
/// </summary>
/// <param name="dontUpdate">Return already existing thread list</param>
/// <returns>Threads collection</returns>
std::vector<Thread>& ProcessThreads::getAll( bool dontUpdate /*= false*/ )
{
    if (dontUpdate)
        return _threads;

    HANDLE hThreadSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );

    _threads.clear();

    if (hThreadSnapshot != INVALID_HANDLE_VALUE)
    {
        THREADENTRY32 tEntry = { 0 };
        tEntry.dwSize = sizeof(THREADENTRY32);

        // Iterate threads
        for (BOOL success = Thread32First( hThreadSnapshot, &tEntry ); 
              success == TRUE;
              success = Thread32Next( hThreadSnapshot, &tEntry ))
        {
            if (tEntry.th32OwnerProcessID != _core.pid())
                continue;

            _threads.emplace_back( Thread( tEntry.th32ThreadID, &_core ) );
        }

        CloseHandle( hThreadSnapshot );
    }

    return _threads;
}
开发者ID:CaptainBigSmoke,项目名称:Blackbone,代码行数:35,代码来源:Threads.cpp

示例14: CreateToolhelp32Snapshot

void runner::enumerate_threads_(std::function<void(handle_t)> on_thread) {
    if (!is_running()) {
        return;
    }
    HANDLE thread_snapshot_h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
    if (thread_snapshot_h == handle_default_value) {
        return;
    }
    THREADENTRY32 thread_entry;
    thread_entry.dwSize = sizeof(thread_entry);
    if (!Thread32First(thread_snapshot_h, &thread_entry)) {
        return;
    }
    do {
        if (thread_entry.dwSize >= FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID) +
            sizeof(thread_entry.th32OwnerProcessID) && thread_entry.th32OwnerProcessID == process_info.dwProcessId) {
            handle_t handle = OpenThread(THREAD_ALL_ACCESS, FALSE, thread_entry.th32ThreadID);
            if (on_thread) {
                on_thread(handle);
            }
            CloseHandle(handle);
        }
        thread_entry.dwSize = sizeof(thread_entry);
    } while (Thread32Next(thread_snapshot_h, &thread_entry));
    CloseHandle(thread_snapshot_h);
}
开发者ID:rotanov,项目名称:Spawner,代码行数:26,代码来源:runner.cpp

示例15: GetMainThreadId

// Плагин может быть вызван в первый раз из фоновой нити (диалог поиска при поиске в архивах)
// Поэтому простой "gnMainThreadId = GetCurrentThreadId();" не прокатит. Нужно искать первую нить процесса!
DWORD GetMainThreadId()
{
	DWORD nThreadID = 0;
	DWORD nProcID = GetCurrentProcessId();
	HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
	if (h != INVALID_HANDLE_VALUE)
	{
		THREADENTRY32 ti = {sizeof(THREADENTRY32)};
		if (Thread32First(h, &ti))
		{
			do {
				// Нужно найти ПЕРВУЮ нить процесса
				if (ti.th32OwnerProcessID == nProcID) {
					nThreadID = ti.th32ThreadID;
					break;
				}
			} while (Thread32Next(h, &ti));
		}
		CloseHandle(h);
	}

	// Нехорошо. Должна быть найдена. Вернем хоть что-то (текущую нить)
	if (!nThreadID) {
		_ASSERTE(nThreadID!=0);
		nThreadID = GetCurrentThreadId();
	}
	return nThreadID;
}
开发者ID:FarManagerLegacy,项目名称:PicView3,代码行数:30,代码来源:PictureView_Utils.cpp


注:本文中的Thread32First函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。