作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试取消对 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/
我对 WlanConnect 的调用可以很好地连接到 AP。但是如果我调用 WNetAddConnectionA 或 WNetAddConnection2A,它们都会返回 0 (NO_ERROR),但
我是一名优秀的程序员,十分优秀!