c++ - TrySubmitThreadpoolCallback 未声明的标识符

标签 c++ winapi

环境

Win10、VC6.0

问题

当我使用windows默认线程池提交worker时, 它编译错误。我用的是VC6.0,包含了Windows.h 但它找不到该功能。请帮助我。

main.cpp

#include "main.h"

int KeyMap[128];



int main()
{
    ScriptHeadTail* pSht = (ScriptHeadTail*)KeyMap[101];
    if (pSht != NULL){
        TrySubmitThreadpoolCallback(ProcessHook, (LPVOID)(pSht->head), NULL);
    }

    Sleep(1000);

    return 1;
}


VOID CALLBACK ProcessHook(PTP_CALLBACK_INSTANCE instance, PVOID lParam)
{
    ExecuteScript* pScript = (ExecuteScript*)lpParam;
    while (pScript != NULL){
        switch (pScript->type)
        {
            case KEYBOARD :
            {
                printf("send key : %d\n", pScript->value);
                break;
            }
            case LBUTTON :
            {
                printf("left button down : %d\n", pScript->value);
                break;
            }
            case RBUTTON :
            {
                break;
            }
            case IDLE :
            {
                Sleep(pScript->value);
                break;
            }
        }
        pScript = pScript->next;
    }
    return 1;
}

ma​​in.h

#include <Windows.h>
#include <stdio.h>


struct ExecuteScript
{
    int type;
    int value;
    ExecuteScript* next;
};

struct ScriptHeadTail
{
    ExecuteScript* head;
    ExecuteScript* tail;
};

BOOL Init(LPCSTR configFile);
BOOL LoadConfigFile(const char* configFile);
VOID CALLBACK ProcessHook(PTP_CALLBACK_INSTANCE instance, PVOID lParam);

const int ASCII_LEN = 128;
const int KEYBOARD = 1;
const int LBUTTON = 2;
const int RBUTTON = 3;
const int IDLE = 4;

结果

--------------------Configuration: ReadFileTest - Win32 Debug---------- ----------
Compiling...
main.cpp
c:\users\jasey\windows-program\readfiletest\main.h(20) : error C2065: 'PTP_CALLBACK_INSTANCE' : undeclared identifier
c:\users\jasey\windows-program\readfiletest\main.h(20) : error C2146: syntax error : missing ')' before identifier 'instance'
c:\users\jasey\windows-program\readfiletest\main.h(20) : warning C4229: anachronism used : modifiers on data are ignored
c:\users\jasey\windows-program\readfiletest\main.h(20) : error C2182: 'ProcessHook' : illegal use of type 'void'
c:\users\jasey\windows-program\readfiletest\main.h(20) : error C2059: syntax error : ')'
c:\users\jasey\windows-program\readfiletest\main.cpp(13) : error C2065: 'TrySubmitThreadpoolCallback' : undeclared identifier
c:\users\jasey\windows-program\readfiletest\main.cpp(60) : error C2146: syntax error : missing ')' before identifier 'instance'
c:\users\jasey\windows-program\readfiletest\main.cpp(60) : warning C4229: anachronism used : modifiers on data are ignored
c:\users\jasey\windows-program\readfiletest\main.cpp(60) : error C2182: 'ProcessHook' : illegal use of type 'void'
c:\users\jasey\windows-program\readfiletest\main.cpp(60) : error C2086: 'ProcessHook' : redefinition
c:\users\jasey\windows-program\readfiletest\main.cpp(60) : error C2059: syntax error : ')'
c:\users\jasey\windows-program\readfiletest\main.cpp(61) : error C2143: syntax error : missing ';' before '{'
c:\users\jasey\windows-program\readfiletest\main.cpp(61) : error C2447: missing function header (old-style formal list?)
执行 cl.exe 时出错.
Creating browse info file...

ReadFileTest.exe - 1 error(s), 0 warning(s)

最佳答案

该 API 是在 Windows Vista 中引入的。 VC 6 支持的最新 Windows SDK 适用于 Windows Server 2003,它比 Vista 更旧。

最好的修复方法是将 Visual C++ 升级到某个较新的版本。

关于c++ - TrySubmitThreadpoolCallback 未声明的标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54033979/

相关文章:

c++ - 是什么导致 C++ std::string 变量在传递给类时给出冲突的定义

c++ - 服务重启后套接字未释放

java - 正确使用异常

c++ - 自定义控件上的文本

c++ - 模拟按住一个键

c++ - 如何将引用绑定(bind)到初始化程序

c++ - 继承构造函数的字符和访问级别

c++ - (key, value)对结构的内存分配,并从注册表中读取

c++ - 一方面背景是透明的,另一方面是上部窗口的标签

c++ - 我们可以从单个线程多次调用 WaitForSingleObject 以获得 Mutex