CancelSynchronousIo与WNetAddConnection2一起使用吗?

我正在尝试并取消与CancelSynchronousIo对WNetAddConnection2的调用。

对CancelSynchronousIo调用成功,但没有任何事实上被取消。

我正在使用在Windows 7 x64上运行的32位控制台应用程序。

有没有人做到这一点成功? 我在做什么愚蠢的事情? 以下是一个示例控制台应用程序(需要与mpr.lib链接):

DWORD WINAPI ConnectThread(LPVOID param) { NETRESOURCE nr; memset(&nr, 0, sizeof(nr)); nr.dwType = RESOURCETYPE_ANY; nr.lpRemoteName = L"\\\\8.8.8.8\\bog"; // result is ERROR_BAD_NETPATH (ie the call isn't cancelled) DWORD result = WNetAddConnection2(&nr, L"pass", L"user", CONNECT_TEMPORARY); return 0; } int _tmain(int argc, _TCHAR* argv[]) { // Create a new thread to run WNetAddConnection2 HANDLE hThread = CreateThread(0, 0, ConnectThread, 0, 0, 0); if (!hThread) return 1; // Retry the cancel until it fails; keep track of how often int count = 0; BOOL ok; do { // Sleep to give the thread a chance to start Sleep(1000); ok = CancelSynchronousIo(hThread); ++count; } while (ok); // count will equal two here (ie one successful cancellation and // one failed cancellation) // err is ERROR_NOT_FOUND (ie nothing to cancel) which makes // sense for the second call DWORD err = GetLastError(); // Wait for the thread to finish; this takes ages (ie the // WNetAddConnection2 call is not cancelled) WaitForSingleObject(hThread, INFINITE); return 0; } 

Solutions Collecting From Web of "CancelSynchronousIo与WNetAddConnection2一起使用吗?"