Win32:无法使用带有stdin句柄的iocp

问题描述 投票:1回答:1

我想在Windows中使用I / O完成端口对stdin进行异步读取,但此代码不起作用:

#include <windows.h>
#include <stdio.h>

#pragma comment(lib, "Kernel32.lib")

int main() {
    HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
    DWORD number;

    HANDLE iocp = CreateIoCompletionPort(handle, NULL, 0, 0);

    if(iocp == NULL) {
        printf("error : %d\n", GetLastError());
    }
}

我收到错误87:ERROR_INVALID_PARAMETER

c asynchronous winapi stdin iocp
1个回答
1
投票

CreateIOCompletionPort不能直接与stdin / stdout一起使用。检查this。使用线程,或将stdin / stdout重定向到命名管道。

© www.soinside.com 2019 - 2024. All rights reserved.