gpt4 book ai didi

windows - CancelSynchronousIo 是否与 WNetAddConnection2 一起使用?

转载 作者:可可西里 更新时间:2023-11-01 10:27:48 26 4
gpt4 key购买 nike

我正在尝试取消对 WNetAddConnection2 的调用,但失败了与 CancelSynchronousIo .

对 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 (i.e. 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 (i.e. one successful cancellation and
// one failed cancellation)

// err is ERROR_NOT_FOUND (i.e. nothing to cancel) which makes
// sense for the second call
DWORD err = GetLastError();

// Wait for the thread to finish; this takes ages (i.e. the
// WNetAddConnection2 call is not cancelled)
WaitForSingleObject(hThread, INFINITE);

return 0;
}

最佳答案

根据 Larry Osterman 的说法(我希望他不介意我引用他的话):“评论中回答了这个问题:wnetaddconnection2 不是一个简单的 IOCTL 调用。”所以答案(不幸的是)是否定的。

关于windows - CancelSynchronousIo 是否与 WNetAddConnection2 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9475581/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com