简体   繁体   中英

WNetAddConnection doesn't fail but doesn't work

My calls to WlanConnect connects fine to the AP. But if I call WNetAddConnectionA or WNetAddConnection2A, they both return 0 (NO_ERROR), but they don't connect to the AP. What's wrong?

EDIT: // added code

NETRESOURCE netResource;
    netResource.dwType = RESOURCETYPE_ANY;
    netResource.lpLocalName = NULL;
    netResource.lpRemoteName = (char *)"\\\\xxx.xxx.xxx.xxx";
    netResource.lpProvider = NULL;
    std::cout << WNetAddConnection2A(&netResource, "password", NULL, 
CONNECT_UPDATE_PROFILE); // prints 0

As the document says, when you set CONNECT_UPDATE_PROFILE flag, the network resource connection should be remembered.

The operating system remembers only successful connections that redirect local devices. It does not remember connections that are unsuccessful or deviceless connections. (A deviceless connection occurs when the lpLocalName member is NULL or points to an empty string.)

Have you tried to use the proper username without NULL?

Best Regards, Baron

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM