TLDR -如果我提供一个类对象作为完成键,则GetQueuedCompletionStatus
不返回,仅当传递结构对象时才返回。
我使用CreateIoCompletionPort
在主线程中创建了IOCP
ShareInfo* l_poShareInfo = new ShareInfo(hDir, p_sSharePath, p_oChangeHandler, dwChangesToMonitor, true);
m_hCompPort = CreateIoCompletionPort(hDir, m_hCompPort, (ULONG_PTR)&l_poShareInfo, 0);
然后我使用GetQueuedCompletionStatus
ShareInfo* l_ShareInfo;
GetQueuedCompletionStatus((HANDLE)l_pThis->m_hCompPort, &nBytes, (PULONG_PTR)&l_ShareInfo, &lpOverlapped, INFINITE);
ShareInfo
是一个如下类,我将其对象用作完成密钥。
class ShareInfo
{
public:
ShareInfo();
ShareInfo(HANDLE p_hDir, const std::wstring & p_sSharePath, FileChangeHandlerBase * p_poChangeHandler, DWORD p_dwChangeFilter, bool p_bWatchSubDir);
~ShareInfo();
OVERLAPPED m_Overlapped;
HANDLE m_hDir;
TCHAR m_sSharePath[MAX_PATH];
CHAR m_Buffer[4096];
DWORD m_dwBufLength;
DWORD m_dwChangeFilter;
FileChangeHandlerBase* m_poChangeHandler;
BOOL m_bWatchSubDir;
};
但是,GetQueuedCompletionStatus
不返回。如果我提供结构对象而不是类对象,则它将按预期工作。因此,我必须按如下方式转换类,并使用ShareInfo::ShareInfoData
对象作为完成密钥。
class ShareInfo
{
public:
.
.
typedef struct
{
OVERLAPPED m_Overlapped;
HANDLE m_hDir;
TCHAR m_sSharePath[MAX_PATH];
CHAR m_Buffer[4096];
DWORD m_dwBufLength;
DWORD m_dwChangeFilter;
FileChangeHandlerBase* m_poChangeHandler;
}ShareInfoData;
ShareInfoData m_shareInfoData;
BOOL m_bWatchSubDir;
};
我怀疑完成键不能是类,但是我在官方文档中找不到任何内容。我在这里缺少基本的东西吗?