Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将extern关键字与CHandle一起用于win32事件_C++_Windows_Multithreading_Winapi - Fatal编程技术网

C++ 将extern关键字与CHandle一起用于win32事件

C++ 将extern关键字与CHandle一起用于win32事件,c++,windows,multithreading,winapi,C++,Windows,Multithreading,Winapi,我正在尝试跨2个文件使用win32事件。所以我用的是extern。 基本上,我从主线程发送一个线程,线程过程在不同的文件中。 我收到一些错误消息:未解析的外部符号: ThreadProcedure.cpp: #include<process.h> #include<afxmt.h> #include<afxwin.h> #include<iostream> using namespace std; UINT __cdecl MyThreadPro

我正在尝试跨2个文件使用win32事件。所以我用的是extern。 基本上,我从主线程发送一个线程,线程过程在不同的文件中。 我收到一些错误消息:未解析的外部符号:

ThreadProcedure.cpp:

#include<process.h>
#include<afxmt.h>
#include<afxwin.h>
#include<iostream>
using namespace std;

UINT __cdecl MyThreadProc(LPVOID lpParameter)
{

    extern CHandle hEvent;
    cout << "waiting for getting signal..." << endl;
    DWORD ret = WaitForSingleObject(hEvent, INFINITE);
    cout << "signaled" << endl;
    // Terminate the thread
    ::AfxEndThread(0, FALSE);
    return 0L;
}
extern HANDLE hEvent;
#包括
#包括
#包括
#包括
使用名称空间std;
UINT\uuu cdecl MyThreadProc(LPVOID lpParameter)
{
钱德勒·海文;

cout在main.cpp中定义一个
HANDLE-hEvent
,在ThreadProcedure.cpp中声明一个extern
CHandle-hEvent
。这些肯定不相同。因此链接器是对的,他没有找到任何
CHandle-hEvent
,只有一个
HANDLE-hEvent
。您需要在声明中给出相同的类型(在ThreadProcedure.cpp中)在定义中(在main.cpp中)

ThreadProcedure.cpp:

#include<process.h>
#include<afxmt.h>
#include<afxwin.h>
#include<iostream>
using namespace std;

UINT __cdecl MyThreadProc(LPVOID lpParameter)
{

    extern CHandle hEvent;
    cout << "waiting for getting signal..." << endl;
    DWORD ret = WaitForSingleObject(hEvent, INFINITE);
    cout << "signaled" << endl;
    // Terminate the thread
    ::AfxEndThread(0, FALSE);
    return 0L;
}
extern HANDLE hEvent;

关于代码的其他注释:C++正在通过C++ Boo> <代码> >代码> false <代码> >代码> CuraEvest< /COD>。<代码> CuraEngult<代码>要求<代码> BooL < /Cube >参数,因此<代码>真< /COD>和<代码> false <代码>。ode>/

false
,编译器需要将其转换为
BOOL


也不要在任何标题中或在
#include
之前使用名称空间std;
编写
(在
之前的main.cpp中,如我在回答的最后一句中所写,包含“header.h”

。可能重复