Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

native WiFi API on Windows XP embedded SP2.

192 views
Skip to first unread message

Raymond Rogers

unread,
Feb 16, 2007, 4:47:23 PM2/16/07
to
I'm trying to use the native WiFi API on a Windows XP embedded system
and I'm not having a lot of luck. I have a test application that works
on my desktop/development system. The same application fails when I
call the WlanSetProfile() function with a return code of 3, and the
reason code is 0. The WlanEnumInterfaces() and
WlanGetAvailableNetworkList() functions work on both platforms. I don't
know if the WlanGetProfileList() or WlanGetProfile() functions work on
XPe because I can't set a profile. I'm assuming that I'm missing some
component from my XPe image, but I have no clue what. I have not been
able to find anything that tells me what this API depends on.

I have also tried the WPS API and it does not work either.

I know that the network interface is installed and working (at least a
little) because it will automatically connect to an open AP.

Milkas

unread,
Feb 17, 2007, 11:14:00 AM2/17/07
to
Wich version of Visual C++ do you use? Do you know not microsoft example on
how to use native Wi-Fi API?

Arkady Frenkel

unread,
Feb 18, 2007, 2:35:12 AM2/18/07
to
Maybe ask that additionally on
microsoft.public.windowsce.platbuilder . obviously embedded XP and CE are
different Oses but modularity of the both system allow to propose that maybe
MSFT guys in charge of that have that knowledge how its done in both

Arkady

"Milkas" <Mil...@discussions.microsoft.com> wrote in message
news:50256A32-8405-48C0...@microsoft.com...

Raymond Rogers

unread,
Feb 19, 2007, 12:22:13 PM2/19/07
to
I'm using VS2005. I have code that works on XP pro but fails on XPe. I
have also tried the AutoConfig sample with the same results. If I install
the device drivers and open my access point it will auto connect so I'm
reasonably sure that the card/drivers are all working. I'm just trying to
figure out what components are required for the native WiFi API. Here is a
list of items I have added trying to get this working:

* MSXML 6.0 is required and I have a component to install it.
* Network Provisioning Service, but I'm not sure if it is required.
* Wireless Zero Configuration
* WindowsXP-KB918997-v6-x86-ENU.exe installed.
* VS2005 runtime libraries (vcredist_x86.exe) installed.
* device drivers for my wireless card.

Can anyone tell me what I might be missing from this list.

"Milkas" <Mil...@discussions.microsoft.com> wrote in message
news:50256A32-8405-48C0...@microsoft.com...

KM

unread,
Feb 19, 2007, 2:39:37 PM2/19/07
to
Raymond,

Assuming the driver got installed correcly (you can check it out in
setupapi.log) it looks like you got all the components required to get this
working.

Am I right assuming you are running your app under Administrator account?
Otherwise, without proper user group setup, it will fail because of not
enough permission. (By default, only a user who is logged on as a member of
the Administrators group or the Network Configuration Operators group can
use the Native Wifi API).
Just before calling WlanSetProfile you may want to check if you got adequate
permissions though a call to WlanGetSecuritySettings.

Wondering if you tried calling Wireless provisioning service API to create
WiFI profile instead? Something like
IProvisioningProfileWireless::CreateProfile.

As has been mentioned in one post here, the following two components are
also nice to have to get WPS API working:
"Simple Network Management Protocol"
"Network Location Awareness Service"

Also, check if "Primitive: Wzcsvc" got into your image config.


If you are saying it works on XP Pro, did you try launching your app on XPe
image with DependencyWalker (Profile feature) running? If not, you amy want
t\o give it a try. Then you either see missing parts or you can compare it
to the same log captured on XP Pro machine. See if there is any difference
in the way how the API call stack works on both OSes.

Regards,
KM

Arkady Frenkel

unread,
Feb 20, 2007, 1:49:20 AM2/20/07
to
Hi, Raymond !

> I'm just trying to figure out what components are required for the native
> WiFi API.
That's why I advised you to ask in platformbuilder NG, there the MSFT guys
know all about components :)
Arkady
"Raymond Rogers" <rero...@symon.com> wrote in message
news:e1pdrpE...@TK2MSFTNGP05.phx.gbl...

devikaahuja

unread,
Nov 25, 2008, 6:12:24 AM11/25/08
to
Hello,

can you please share the code to execute the Native Wifi API.I am getting error as error C2065: 'WlanOpenHandle' : undeclared identifier

Which header file i need to include and whar are the project settings that are required to be done?

Pavel A.

unread,
Nov 25, 2008, 7:04:53 AM11/25/08
to

You need the latest Windows Platform SDK, that contains wlanapi.h.
Will post a small example when I get to my PC.

Regards,
--PA

Pavel A.

unread,
Nov 26, 2008, 12:13:34 AM11/26/08
to
Ok, here's a small example for WinXP SP3 or SP2 with KB918997.
It enables or disables WZC to control wi-fi adapters.
Add the SDK include dir to include paths and SDK lib dir to the lib path.

Regards,
--PA

------------- cut here ----------
// Usage: onoff.exe on|off
// pavel_a 04-jan-2007, built with Vista RTM SDK, vs2005

#include "stdafx.h"
#include <windows.h>
#include <wlanapi.h>
#pragma comment( lib, "wlanapi.lib")

#define tprintf _tprintf

static PTSTR rs2str( DOT11_RADIO_STATE rs )
{
switch(rs) {
case dot11_radio_state_on: return TEXT("on");
case dot11_radio_state_off: return TEXT("off");
default: return TEXT("undef");
}
}

static PTSTR ifstate2str( WLAN_INTERFACE_STATE rs )
{
switch(rs) {
default: return TEXT("undef");
case wlan_interface_state_not_ready: return TEXT("not_ready");
case wlan_interface_state_connected: return TEXT("connected");
case wlan_interface_state_ad_hoc_network_formed: return
TEXT("adhoc_formed");
case wlan_interface_state_disconnecting: return
TEXT("disconnecting");
case wlan_interface_state_disconnected: return TEXT("not
connected");
case wlan_interface_state_associating: return TEXT("associating");
case wlan_interface_state_discovering: return TEXT("discovering");
case wlan_interface_state_authenticating: return
TEXT("authenticating");
}
}

void OnOff( int a_on )
{
DWORD dwNegotiatedVersion = 0;
HANDLE hClient = NULL;
UINT i;
DWORD r;

PWLAN_INTERFACE_CAPABILITY pCapability = NULL;
PWLAN_INTERFACE_INFO_LIST pIntfList = NULL;
BOOL aenabled = FALSE, newstate = FALSE;

r = WlanOpenHandle( WLAN_API_VERSION, NULL, &dwNegotiatedVersion,
&hClient );
if( ERROR_SUCCESS != r )
{
tprintf( TEXT("Error opening Wlanapi=%u\n"), r );
return;
}

tprintf( _T("WlanAPI version available=%8.8x\n"), dwNegotiatedVersion );

r = WlanEnumInterfaces(hClient, NULL, &pIntfList);

if( ERROR_SUCCESS != r )
{
tprintf( TEXT("Error in WlanEnumInterfaces=%u\n"), r );
return;
}

for( i = 0; i < pIntfList->dwNumberOfItems; i++ )
{
PWLAN_INTERFACE_INFO pwi = &pIntfList->InterfaceInfo[i];
PWSTR descr = pwi->strInterfaceDescription;
GUID& guidIntf = pwi->InterfaceGuid;
WLAN_INTERFACE_STATE st = pwi->isState;

wprintf( TEXT("Adapter=[%s] state=%u (%s)\n"), descr, (UINT)st,
ifstate2str(st) );

if( st == wlan_interface_state_not_ready )
{
tprintf(TEXT("Interface not ready\n"));
continue;
}

ULONG outsize = 0;
PBOOL pb = NULL;

r = WlanQueryInterface( hClient, &guidIntf,
wlan_intf_opcode_autoconf_enabled, NULL, &outsize, (PVOID*)&pb, NULL );

if( ERROR_SUCCESS != r )
{
tprintf( TEXT("Error WlanQueryInterface(autoconf) =%u\n"), r );
continue;
}

aenabled = *pb & 0xFF;

WlanFreeMemory( pb );

tprintf( TEXT("Autoconfig enabled: %s\n"), aenabled ?
_T("yes"):_T("no") );

if( !a_on && aenabled )
{
newstate = 0; // FALSE
}

if( a_on && !aenabled )
{
newstate = 0xFF; // TRUE
}

r = WlanSetInterface( hClient, &guidIntf,
wlan_intf_opcode_autoconf_enabled, 4, (PVOID)&newstate, NULL );

if( r != ERROR_SUCCESS ) {
tprintf( TEXT("SetInterface error=%d\n"), r );
continue;
}

tprintf( TEXT("SetInterface ok\n") );

// NOTE: If the adapter was connected, it still stays connected;
// WZC just won't touch it any longer.
// We don't call WlanDisconnect because on XP this may convert an
// automatic profile to on-demand (see MSDN)
// After enabling WZC, you can restore connection manually,
// or call WlanConnect with some profile or SSID.
}//for

if (pIntfList != NULL) {
WlanFreeMemory(pIntfList);
}

if (hClient != NULL) {
WlanCloseHandle(hClient, NULL);
}
}


int _tmain(int argc, _TCHAR* argv[])
{
if( !argv[1] ) return 1;

if( 0 == wcscmp( TEXT("off"), argv[1] ) ) {
OnOff( 0 );
} else if( 0 == wcscmp( TEXT("on"), argv[1] ) ) {
OnOff( 1 );
}
else return 2;

return 0;
}
----------- cut here -------------


"Pavel A." <pav...@NOfastmailNO.fm> wrote in message
news:eopnuYvT...@TK2MSFTNGP06.phx.gbl...

devikaahuja

unread,
Dec 2, 2008, 8:01:04 AM12/2/08
to
Thanks for your help.I wrote the code and got it compiled too.But now i am facing linker issues.

WirelessAutoConfigDlg.obj : error LNK2019: unresolved external symbol _WlanCloseHandle@8 referenced in function "public: void __thiscall CWirelessAutoConfigDlg::OnBnClickedButton1(void)" (?OnBnClickedButton1@CWirelessAutoConfigDlg@@QAEXXZ)

Although i have inclided the path of the lib file in the the Project roperties\Linker\General\Additional Library directeries.

I opened the lib and saw that these functions are present in the lib with the same name after being mangled.

What can be the possible reasons for the error.

Pavel A.

unread,
Dec 2, 2008, 1:13:53 PM12/2/08
to

Only WlanCloseHandle is unresolved and not others?

--PA

Ahuja@discussions.microsoft.com Devika Ahuja

unread,
Jan 9, 2009, 7:17:11 AM1/9/09
to
Hi
I was able to build the apllication successfully .But when i try to call
WlansetProfile.it is giving me dwError == ERROR_BAD_PROFILE

my profile is very simple:
<?xml version="1.0" ?>
<WLANProfile
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>NetTest1-adhoc</name>
<SSIDConfig>
<SSID>
<name>NetTest1</name>
</SSID>
</SSIDConfig>
<connectionType>IBSS</connectionType>
<MSM>
<security>
<authEncryption>
<authentication>open</authentication>
<encryption>NONE</encryption>
</authEncryption>
</security>
</MSM>
</WLANProfile>

Here is my code that i am using
void CWirelessAutoConfigDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here


HANDLE hClient = NULL;
DWORD dwError = ERROR_SUCCESS;
DWORD dwServiceVersion;
DWORD dwReason;
PWLAN_INTERFACE_INFO_LIST pIntfList = NULL;
CComPtr<IXMLDOMDocument2> pXmlDoc;
CComBSTR bstrXml;
VARIANT_BOOL vbSuccess;
HRESULT hr;


dwError = WlanOpenHandle(
WLAN_API_VERSION,
NULL, // reserved
&dwServiceVersion,
&hClient
);
dwError = WlanEnumInterfaces(hClient, NULL, &pIntfList);

hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
// create a COM object to read the XML file
hr = CoCreateInstance(
CLSID_DOMDocument60,
NULL,
CLSCTX_INPROC_SERVER,
IID_IXMLDOMDocument2,
(void**)&pXmlDoc
);
CComVariant varFile;
varFile = "D:\\wirelessProfile3.xml";
hr = pXmlDoc->load(varFile, &vbSuccess);
hr = pXmlDoc->get_xml(&bstrXml);
dwError = WlanSetProfile(
hClient,
&pIntfList->InterfaceInfo[ 0 ].InterfaceGuid,
0, // no flags for the profile
bstrXml, //wsProfileXml,
NULL, // use the default ACL
TRUE, // overwrite a profile if it already exists
NULL, // reserved
&dwReason
);

dwError = WlanCloseHandle(
hClient,
NULL // reserved
);
}

Can you please help me out in finding the cause of the problem.Thanks in
advance.
Devika

Pavel A.

unread,
Jan 10, 2009, 5:40:29 PM1/10/09
to
Devika Ahuja wrote:
> Hi
> I was able to build the apllication successfully .But when i try to call
> WlansetProfile.it is giving me dwError == ERROR_BAD_PROFILE


From MSDN: "If this value is returned, pdwReasonCode specifies the
reason the profile is invalid." What is dwReason value on return?

--PA

0 new messages