【C++】在子线程中调用c++类的成员函数——7
发布日期:2021-05-15 02:52:02 浏览次数:19 分类:精选文章

本文共 2506 字,大约阅读时间需要 8 分钟。

������������������������������������������������������������

������������������������������������Win32 API������������������������������������������������������������������������������������������������������������������������������������

���������������

������������������������������������������������������������������������������������������������������������

  • ���test.h���������������������������������������������������������������������
  • ������������������������������������������������������������������������������������������������
  • ���test.cpp���������������������������������������������������������������������������
  • ���������������

    1. ���������������

    • ������������static������������������������

      • ���test.h������static������������������������������������������������������������������������������������������

      ���������������

      class Test {
      public:
      static void check();
      static DWORD WINAPI Fun(LPVOID lpParamter);
      };

    2. ���������������������

    ���main.cpp������������CreateThread������������������������������ startup routine���������������������������������������������_lpThreadId��������� ID���������������������������������������������������0������������������������������������������0������

    ���������

    HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Test::Fun, &test, 0, NULL);

    ������������������������������������������������������Test::Fun������������������������������������������Test������������������������������������

    3. ���������������������������

    ���test.cpp������������������������������������������������������������ ���������������

    Test *plocal = (Test*)lpParamter;
    plocal->check();

    4. ���������������������������������

    ������GetLastError������������������������������������������������

    if (hThread == NULL) {
    int lastError = GetLastError();
    cout << "���������������������������������" << lastError << endl;
    }

    ���������������������

    • ���������������Windows 10 ��� newer
    • ���������������Visual Studio ��� MinGW-w64
    • ������������������<windows.h>���<iostream>������������

    ���������������������

    • ������������������0 : Main Thread Display!
    • ������������������0 : Fun A Thread Fun Display!!

    ���������������������������������������������������������������������

    ���������������

    • ������������������������������������������������
    • ������������Test���������������
    • static���������������������
    • ������������������������ DWORD������������0������������������

    ���������������������������������������������������������������������������������������������������������������������������������

    上一篇:【C++】pinv()函数原型以及matlab中的pinv() —— 8
    下一篇:【C++】Windows下多个子线程互斥——6

    发表评论

    最新留言

    网站不错 人气很旺了 加油
    [***.192.178.218]2025年04月14日 23时13分09秒

    关于作者

        喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
    -- 愿君每日到此一游!

    推荐文章