进程线程简单笔记

时间:2022-02-02 18:06:57

一 进程的函数

 1 创建进程

BOOL WINAPI CreateProcess(
  _In_opt_    LPCTSTR               lpApplicationName,
  _Inout_opt_ LPTSTR                lpCommandLine,
  _In_opt_    LPSECURITY_ATTRIBUTES lpProcessAttributes,
  _In_opt_    LPSECURITY_ATTRIBUTES lpThreadAttributes,
  _In_        BOOL                  bInheritHandles,
  _In_        DWORD                 dwCreationFlags,
  _In_opt_    LPVOID                lpEnvironment,
  _In_opt_    LPCTSTR               lpCurrentDirectory,
  _In_        LPSTARTUPINFO         lpStartupInfo,
  _Out_       LPPROCESS_INFORMATION lpProcessInformation
);
HINSTANCE ShellExecute(
  _In_opt_ HWND    hwnd,
  _In_opt_ LPCTSTR lpOperation,
  _In_     LPCTSTR lpFile,
  _In_opt_ LPCTSTR lpParameters,
  _In_opt_ LPCTSTR lpDirectory,
  _In_     INT     nShowCmd
);

BOOL ShellExecuteEx(
  _Inout_ SHELLEXECUTEINFO *pExecInfo // SHELLEXECUTEINFO::lpVerb =="runas" 时, 提示使用管理员启动
lpVerb
);

2 结束进程
VOID WINAPI ExitProcess(UINT uExitCode);// 进程结束自己
BOOL WINAPI TerminateProcess(HANDLE hProcess,UINT   uExitCode);//异步结束其他进程

二   线程的函数

 1 创建线程

HANDLE WINAPI CreateThread(
  _In_opt_  LPSECURITY_ATTRIBUTES  lpThreadAttributes,
  _In_      SIZE_T                 dwStackSize,
  _In_      LPTHREAD_START_ROUTINE lpStartAddress,
  _In_opt_  LPVOID                 lpParameter,
  _In_      DWORD                  dwCreationFlags,
  _Out_opt_ LPDWORD                lpThreadId
);

2 结束线程
VOID WINAPI ExitThread(DWORD dwExitCode); // 线程结束自己, 结束后线程的堆栈被销毁
BOOL WINAPI TerminateThread(HANDLE hThread,DWORD  dwExitCode);// 异步结束其他线程, 结束后除非拥有此线程的进程终止运行, 否则线程的堆栈不会被销毁

C++运行库函数
_beginthreadex
_endthreadex