Win API:之GetCurrentThread、GetCurrentThreadId、GetCurrentProcess、GetCurrentProcessId
Win API:之GetCurrentThread、GetCurrentThreadId、GetCurrentProcess、GetCurrentProcessId
{返回当前线程的虚拟句柄} GetCurrentThread: THandle;
{返回当前线程 ID} GetCurrentThreadId: DWORD;
{返回当前进程的虚拟句柄} GetCurrentProcess: THandle;
{返回当前进程 ID} GetCurrentProcessId: DWORD;
提示:
ID 是系统唯一的标识.
所谓虚拟句柄, 就是该句柄只在调用进程的进程中有效, 也不能被继承;
如果用于其他进程需要用 DuplicateHandle 复制句柄;
GetCurrentProcess 返回的虚拟句柄可以通过 OpenProcess 创建一个真实的句柄.
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
#include <iostream>
#include <Windows.h> #include <process.h> #include <tchar.h> #include <strsafe.h> #define BUF_SIZE typedef struct MyData { using namespace std; DWORD WINAPI MyThread( LPVOID lpParam ); int main(void) hProcess = GetCurrentProcess(); //进程伪句柄 if( pData == NULL ) cin.get(); DWORD WINAPI MyThread( LPVOID lpParam ) HANDLE hStdout; TCHAR msgBuf[BUF_SIZE] = {}; hStdout = GetStdHandle(STD_OUTPUT_HANDLE); // Cast the parameter to the correct data type. // Print the parameter values using thread-safe functions. return ; } |
最新文章
- 关于 C# 调用 JavaWebservice服务,版本不一致的问题
- C++ 一个统计文件夹下所有代码文件行数的小工具
- C# WinForm 技巧八:界面开发之&ldquo;WeifenLuo.WinFormsUI.Docking+OutLookBar&rdquo; 使用
- asp 回发的时候样式变化
- Digital Root - SGU 118(高精度运算)
- Session 原理
- zoj1183 Scheduling Lectures
- [ML]机器学习书单
- LFYZ-OJ ID: 1009 阶乘和
- java代理通俗简单解析
- linux 命令 — cut
- ThreadLocal 类 的源码解析以及使用原理
- JAVA方法调用中的解析与分派
- Python执行ImportError:No module named MySQLdb异常
- JVM内存管理--分代搜集算法
- 微信小程序开发工具
- PHP开发环境安装说明书
- HDU 1896 Stones (优先队列)
- nexus 手动更改 私服包
- 一、redis系列之基础知识与centos下环境搭建