Retrieve the number of opened file descriptors using the Windows API

浪尽此生 提交于 2019-12-04 16:51:13

You can ask each handle in the process using GetFileType.

      DWORD type_char = 0, 
      type_disk = 0, 
      type_pipe = 0, 
      type_remote = 0, 
      type_unknown = 0,
      handles_count = 0;

GetProcessHandleCount(GetCurrentProcess(), &handles_count);
handles_count *= 4;
for (DWORD handle = 0x4; handle < handles_count; handle += 4) {
    switch (GetFileType((HANDLE)handle)){
        case FILE_TYPE_CHAR:
            type_char++;
            break;
        case FILE_TYPE_DISK:
            type_disk++;
            break;
        case FILE_TYPE_PIPE: 
            type_pipe++;
            break;
        case FILE_TYPE_REMOTE: 
            type_remote++;
            break;
        case FILE_TYPE_UNKNOWN:
            if (GetLastError() == NO_ERROR) type_unknown++;
            break;

    }

}

If you are after checking open handles then you can the Handle utility from SysInternals.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!