Connect to WiFi

I work mostly with microcontrollers, but sometimes I have a need to make a Windows based application that will either test some code that will later be ported to a microcontroller, or to test some communication issue. The level of Windows programming I do explains why I still do all my code in C/C++ and MFC.
I now have a need to programmatically connect to WiFi from a Windows application (to a microcontroller which is in AP mode). Some old documents I found online suggest that Native WiFi APIs can be used for this purpose and I found some examples as well (https://github.com/microsoft/Windows-classic-samples/blob/main/Samples/Win7Samples/netds/wlan/autoconfig/wlsample.cpp). Including wlanapi.h is not a problem, but linking to wlanapi.lib gives me a tons of linker errors.
What I do is – I edit solution properties / linker / general / additional library directories and add C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\um\x64 as this is the only folder where I found wlanapi.lib. However, like I said, I get all kind of linking errors.
Can you please be so kind to tell me what is the best way to programmatically connect to WiFi with the “old” technology that I use.
Thank you.
Thank you very much for your quick response.
Here is the list of linker error I'm getting from Visual Studio Pro 2019.
There must be something wrong that I'm doing related to the project configuration, but I don't know what.
I would really appreciate any suggestions.
Of course, I'm in no way obliged to use this method to programmatically connect to WiFi, so if there is another, maybe even simpler way I can use with my environment, please let me know.
Thank you.
P.S. Sorry for having to put the list of errors in the posts below. The posting form didn't allow me to put it all here.
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol __imp__RpcStringFreeW@4 referenced in function "void __cdecl EnumInterface(int,wchar_t * * const)" (?EnumInterface@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol __imp__UuidToStringW@8 referenced in function "void __cdecl EnumInterface(int,wchar_t * * const)" (?EnumInterface@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol __imp__UuidFromStringW@8 referenced in function "void __cdecl SetProfile(int,wchar_t * * const)" (?SetProfile@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanOpenHandle@16 referenced in function "unsigned long __cdecl OpenHandleAndCheckVersion(void * *)" (?OpenHandleAndCheckVersion@@YAKPAPAX@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanCloseHandle@8 referenced in function "void __cdecl RegisterNotification(int,wchar_t * * const)" (?RegisterNotification@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanEnumInterfaces@12 referenced in function "void __cdecl EnumInterface(int,wchar_t * * const)" (?EnumInterface@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanGetInterfaceCapability@16 referenced in function "void __cdecl GetInterfaceCapability(int,wchar_t * * const)" (?GetInterfaceCapability@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanSetInterface@24 referenced in function "void __cdecl SetRadioState(int,wchar_t * * const)" (?SetRadioState@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanQueryInterface@28 referenced in function "void __cdecl GetInterfaceCapability(int,wchar_t * * const)" (?GetInterfaceCapability@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanScan@20 referenced in function "void __cdecl Scan(int,wchar_t * * const)" (?Scan@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanGetAvailableNetworkList@20 referenced in function "void __cdecl GetVisibleNetworkList(int,wchar_t * * const)" (?GetVisibleNetworkList@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanGetNetworkBssList@28 referenced in function "void __cdecl GetBssList(int,wchar_t * * const)" (?GetBssList@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanConnect@16 referenced in function "void __cdecl Connect(int,wchar_t * * const)" (?Connect@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanDisconnect@12 referenced in function "void __cdecl Disconnect(int,wchar_t * * const)" (?Disconnect@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanRegisterNotification@28 referenced in function "void __cdecl RegisterNotification(int,wchar_t * * const)" (?RegisterNotification@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanGetProfile@28 referenced in function "void __cdecl GetProfile(int,wchar_t * * const)" (?GetProfile@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanSetProfile@32 referenced in function "void __cdecl SetProfile(int,wchar_t * * const)" (?SetProfile@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanDeleteProfile@16 referenced in function "void __cdecl DeleteProfile(int,wchar_t * * const)" (?DeleteProfile@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanGetProfileList@16 referenced in function "void __cdecl GetProfileList(int,wchar_t * * const)" (?GetProfileList@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanSetProfileList@20 referenced in function "void __cdecl SetProfileList(int,wchar_t * * const)" (?SetProfileList@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanSaveTemporaryProfile@28 referenced in function "void __cdecl SaveTemporaryProfile(int,wchar_t * * const)" (?SaveTemporaryProfile@@YAXHQAPA_W@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanReasonCodeToString@16 referenced in function "void __cdecl PrintReason(unsigned long)" (?PrintReason@@YAXK@Z)
1>WiFiCtrl.obj : error LNK2019: unresolved external symbol _WlanFreeMemory@4 referenced in function "void __cdecl GetProfile(int,wchar_t * * const)" (?GetProfile@@YAXHQAPA_W@Z)
1>C:\Projects\Windows\EIMUpdater\Debug\EIMUpdater.exe : fatal error LNK1120: 23 unresolved externals
Update:
I just added wlanapi.lib to "project properties / linker / input / additional dependencies" and it looks like this fixed all Wlan... related link errors. The only remaining ones are these:
error LNK2019: unresolved external symbol __imp__RpcStringFreeW@4 referenced in function "void __cdecl EnumInterface(int,wchar_t * * const)" (?EnumInterface@@YAXHQAPA_W@Z)
error LNK2019: unresolved external symbol __imp__UuidToStringW@8 referenced in function "void __cdecl EnumInterface(int,wchar_t * * const)" (?EnumInterface@@YAXHQAPA_W@Z)
error LNK2019: unresolved external symbol __imp__UuidFromStringW@8 referenced in function "void __cdecl SetProfile(int,wchar_t * * const)" (?SetProfile@@YAXHQAPA_W@Z)
Do you have any idea how to fix these?
Thank you.
Sign in to comment
Hello,
Welcome to Microsoft Q&A!
I see the file shows that the last modification time is 2006. I cannot run it directly in VS2019, so we need to modify the project properties.
Project -> Properties -> Platform Toolset (choose Visual Studio 2012 (v110) )
Under normal circumstances, there is no V110 option in VS2019, you need to download VS2012, after the download and installation is complete, V110 will appear in VS2019.
Thank you.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Thank you very much for your input.
Just a quick question - is it OK to have both VS2019 and VS2012 installed at the same time, or I have to remove VS2019 before installing VS2012?
It is OK to have multiple versions of VS at the same time.
Does the code now run successfully?
Sign in to comment
0 additional answers
Sort by: Most helpful
Activity