sprintf_s failed in release mode, and ok in debug - c++

In C++, with VS2012, i would like to get the Mac adress and convert it in car formatting.
I Use sprintf_s function() in order to convert in car mode.
In debug mode, all is ok, but, in release mode, the sprint_s function don't execute properly ! It appear to exit my programm !
I don't know why !
Anyone could help me please ?
Here is a little sample which demonstrate my problem. I tested in on severals pc's :
#include "stdafx.h"
#include <winsock2.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <stdlib.h>
#pragma comment(lib, "iphlpapi.lib")
#define MACADDR_SIZE (6*3)
#define MAC_DIM 6
#define MACHINE_CODE_DIM 6
#define SOFTWAREKEY_DIM 6
enum RETVALUE
{
SUCCESS,
ERROR_API_CALL_FAILED,
ERROR_FAILURE_WHILE_LOADING_LIBRARY,
ERROR_OS_VERSION_NOT_SUPPORTED,
ERROR_SOFTWAREKEY_NOT_FOUND,
ERROR_CONVERSION_CHAR_2_WCHAR_FAILED
};
int _tmain(int argc, _TCHAR* argv[])
{
char * mac_addr = (char*)malloc(MACADDR_SIZE + 1);
// Declare and initialize variables
DWORD dwSize = 0;
DWORD dwRetVal = 0;
int i = 0;
ULONG flags, outBufLen = 0, family;
LPVOID lpMsgBuf;
PIP_ADAPTER_ADDRESSES pAddresses;
PIP_ADAPTER_ADDRESSES pCurrAddresses;
PIP_ADAPTER_UNICAST_ADDRESS pUnicast;
PIP_ADAPTER_ANYCAST_ADDRESS pAnycast;
PIP_ADAPTER_MULTICAST_ADDRESS pMulticast;
IP_ADAPTER_DNS_SERVER_ADDRESS *pDnServer = NULL;
IP_ADAPTER_PREFIX *pPrefix = NULL;
// Set the flags to pass to GetAdaptersAddresses
flags = GAA_FLAG_INCLUDE_PREFIX;
// default to unspecified address family (both)
family = AF_UNSPEC;
lpMsgBuf = NULL;
pAddresses = NULL;
pCurrAddresses = NULL;
pUnicast = NULL;
pAnycast = NULL;
pMulticast = NULL;
family = AF_INET;
outBufLen = sizeof (IP_ADAPTER_ADDRESSES);
pAddresses = (IP_ADAPTER_ADDRESSES *)malloc(outBufLen);
if (pAddresses == NULL)
{
printf("Memory allocation failed for IP_ADAPTER_ADDRESSES struct!\n");
exit(1);
}
else
printf("Memory allocation for IP_ADAPTER_ADDRESSES struct is OK!\n");
// Make an initial call to GetAdaptersAddresses to get the
// size needed into the outBufLen variable
if (GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen) == ERROR_BUFFER_OVERFLOW)
{
printf("Not enough buffer! Re-allocating...\n");
free(pAddresses);
pAddresses = (IP_ADAPTER_ADDRESSES *)malloc(outBufLen);
}
else
printf("Buffer allocation is OK!\n");
if (pAddresses == NULL)
{
printf("Memory allocation failed for IP_ADAPTER_ADDRESSES struct!\n");
exit(1);
}
else
printf("Memory allocation for IP_ADAPTER_ADDRESSES struct is OK!\n");
// Make a second call to GetAdapters Addresses to get the actual data we want
printf("Memory allocated for GetAdapterAddresses = %d bytes\n", outBufLen);
printf("Calling GetAdaptersAddresses function with family = ");
if (family == AF_INET)
printf("AF_INET\n");
dwRetVal = GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen);
if (dwRetVal == NO_ERROR)
{
// If successful, output some information from the data we received
pCurrAddresses = pAddresses;
if (pCurrAddresses->PhysicalAddressLength != 0)
{
printf("\tPhysical address: ");
for (i = 0; i < (int)pCurrAddresses->PhysicalAddressLength; i++)
{
if (i == (pCurrAddresses->PhysicalAddressLength - 1))
printf("%.2X\n", (int)pCurrAddresses->PhysicalAddress[i]);
else
printf("%.2X-", (int)pCurrAddresses->PhysicalAddress[i]);
}
}
sprintf_s(mac_addr, MACADDR_SIZE + 1, "%c%c%c%c%c%c",
pCurrAddresses->PhysicalAddress[0], pCurrAddresses->PhysicalAddress[1],
pCurrAddresses->PhysicalAddress[2], pCurrAddresses->PhysicalAddress[3],
pCurrAddresses->PhysicalAddress[4], pCurrAddresses->PhysicalAddress[5]);
printf("Mac adress in car formatting is :");
printf(mac_addr);
getchar();
free(pAddresses);
}
return 0;
}
Thanks a lot :)
Best regards,
Nixeus

You can't use %c to print the bytes of a MAC address, as those bytes may not be printable characters.
The code that printf "Physical address" using %.2X is the one to use.
Your code works well in Debug or Release mode for me (VS2012), but as my first NIC has 0x00 as first byte, the final printf prints nothing.

Related

How can I read a vector of structures in a mapped-file?

I have 2 programs, one gets all processes information using Windows API and stores them in a vector of structure like this:
struct Info{
int pid,ppid;
char exeName[256];
}
I keep back_pushing structure in vector when i populate a structure with data.
Now, I've tried to use memcpy() to memorize data in mapped-file but I can't read it properly in the second program. Can you help me to figure out how to read data properly?
Code program 1:
#define _CRT_SECURE_NO_WARNINGS
#include <Windows.h>
#include <stdio.h>
#include <Tlhelp32.h>
#include <vector>
struct InfoProces {
DWORD pid;
DWORD ppid;
char exeName[256];
};
int main(){
HANDLE hProcesses;
PROCESSENTRY32 pe32;
hProcesses = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if (hProcesses == INVALID_HANDLE_VALUE)
{
printf("CreateToolhelp32Snapshot failed. err = %d", GetLastError());
return -1;
}
pe32.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(hProcesses, &pe32)) {
printf("Process32First failed. err = %d", GetLastError());
CloseHandle(hProcesses);
return -1;
}
HANDLE hdata = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 1024 * 1024, "data");
if (hdata == NULL) {
printf("Can't create a file mapping. err = %d", GetLastError());
return -1;
}
unsigned char* pdata = (unsigned char*)MapViewOfFile(hdata, FILE_MAP_WRITE, 0, 0, 0);
if (pdata == NULL) {
printf("cant get pointer to mapping file. err = %d", GetLastError());
return -1;
}
do {
InfoProces pi;
pi.pid = pe32.th32ProcessID;
pi.ppid = pe32.th32ParentProcessID;
strcpy(pi.exeName, pe32.szExeFile);
} while (Process32Next(hProcesses, &pe32));
getchar();
CloseHandle(hProcesses);
return 0;
Code program 2:
#define _CRT_SECURE_NO_WARNINGS
#include <Windows.h>
#include <vector>
#include <stdio.h>
struct InfoProces {
DWORD pid;
DWORD ppid;
char exeName[256];
};
int main()
{
HANDLE hdata = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, "data");
unsigned char* pdata = (unsigned char*)MapViewOfFile(hdata, FILE_MAP_READ, 0, 0, 0);
if (pdata == NULL) {
printf("cant get pointer to mapped file. err = %d", GetLastError());
return -1;
}
std::vector<InfoProces>processes;
memcpy(&processes,pdata,sizeof(data));
for (std::vector<InfoProces>::iterator i = processes.begin(); i < processes.end(); i++)
printf("Process[%d](parinte[%d]): %s\n", i->pid, i->ppid, i->exeName);
return 0;
}
As the comment pointed out, you have got the starting address of the mapped view(pdata), You can only use the pdata for memory sharing, but not any stack address of the process.
Try to copy the memory of InfoProces to the pdata in program 1:
memcpy(pdata, &pi, sizeof(InfoProces));
In addition, in program 2, you did not set the size for the vector, and you should replace &processes with processes.data(). You also need to know the size of the array you added in program 1:
std::vector<InfoProces> processes;
processes.resize(count);
memcpy(processes.data(), pdata, sizeof(InfoProces)*count);
Following code works for me.
Program 1:(Record the count of InfoProces and save it to a DWORD in the beginning of pdata)
...
unsigned char* pdata = (unsigned char*)MapViewOfFile(hdata, FILE_MAP_WRITE, 0, 0, 0);
if (pdata == NULL) {
printf("cant get pointer to mapping file. err = %d", GetLastError());
return -1;
}
unsigned char* begin = pdata;
//offset a size of DWORD;
DWORD count = 0;
pdata += sizeof(DWORD);
do {
InfoProces pi;
pi.pid = pe32.th32ProcessID;
pi.ppid = pe32.th32ParentProcessID;
strcpy(pi.exeName, pe32.szExeFile);
memcpy(pdata, &pi, sizeof(InfoProces));
pdata += sizeof(InfoProces);
count++;
} while (Process32Next(hProcesses, &pe32));
memcpy(begin, &count, sizeof(DWORD));
getchar();
UnmapViewOfFile(begin);
CloseHandle(hdata);
CloseHandle(hProcesses);
...
Program 2:
...
unsigned char* pdata = (unsigned char*)MapViewOfFile(hdata, FILE_MAP_READ, 0, 0, 0);
if (pdata == NULL) {
printf("cant get pointer to mapped file. err = %d", GetLastError());
return -1;
}
unsigned char* begin = pdata;
DWORD count = 0;
memcpy(&count, pdata, sizeof(DWORD));
pdata += sizeof(DWORD);
std::vector<InfoProces> processes;
processes.resize(count);
memcpy(processes.data(), pdata, sizeof(InfoProces)*count);
for (std::vector<InfoProces>::iterator i = processes.begin(); i < processes.end(); i++)
printf("Process[%d](parinte[%d]): %s\n", i->pid, i->ppid, i->exeName);
UnmapViewOfFile(begin);
CloseHandle(hdata);
...
Finally, do not forget to close the handle and unmap address.

Finding USB comport numbers using VID,PID,+SN

I am looking for example code in ansi c/c++ that will find usb devices by their pid/vid/sn# and then find the associated comport number. I have multiple FTDI usb serial ports connected to a pc and need to identify each port by the known SN#. This code I found will display the HWID info but how do I use it to get the comport number? Here is a response to the below code for one of the devices: USB\VID_0403&PID_6001\FTAME7HK
Are there an online tutorial that runs through examples for this type of code?
#include <windows.h>
#include <ansi_c.h>
#include <Setupapi.h>
#include <devguid.h>
#include <Setupapi.h>
HDEVINFO deviceInfoSet;
GUID *guidDev = (GUID*) &GUID_DEVCLASS_USB;
TCHAR buffer [4000];
DWORD buffersize =4000;
int memberIndex = 0;
main()
{
deviceInfoSet = SetupDiGetClassDevs(guidDev, NULL, NULL, DIGCF_PRESENT | DIGCF_PROFILE);
while (TRUE) {
SP_DEVINFO_DATA deviceInfoData;
ZeroMemory(&deviceInfoData, sizeof(SP_DEVINFO_DATA));
deviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
if (SetupDiEnumDeviceInfo(deviceInfoSet, memberIndex, &deviceInfoData) == FALSE) {
if (GetLastError() == ERROR_NO_MORE_ITEMS)
{
break;
}
}
DWORD nSize=0 ;
SetupDiGetDeviceInstanceId (deviceInfoSet, &deviceInfoData, buffer, sizeof(buffer), &nSize);
buffer [nSize] ='\0';
printf ("%s\n", buffer);
memberIndex++;
}
if (deviceInfoSet) {
SetupDiDestroyDeviceInfoList(deviceInfoSet);
}
getchar();
return 0;
}
If you want the friendly name, which typically includes the parenthesized com port number, this should do it:
{
wchar_t friendly_name[128];
if (!SetupDiGetDeviceRegistryPropertyW(device_list, &device_data, SPDRP_FRIENDLYNAME, nullptr, reinterpret_cast<PBYTE>(friendly_name), sizeof friendly_name, nullptr))
return;
StringCopyW(buffer, friendly_name);
}
To get the two parameters device_list and device_data for the above call, I use this function:
void rescan_ports( void )
{
SP_DEVINFO_DATA device_data = { sizeof device_data };
HDEVINFO device_list = SetupDiGetClassDevsW(&GUID_DEVINTERFACE_COMPORT, nullptr, nullptr, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
DWORD error = GetLastError();
if (!device_list && device_list == INVALID_HANDLE_VALUE) return;
bool ended = false;
for( int i = 0; i < 6000 && !ended; i++ ) {
if (SetupDiEnumDeviceInfo(device_list, i, &device_data))
format_and_add_port_detail(device_list, device_data);
else
ended = (GetLastError() == ERROR_NO_MORE_ITEMS);
}
SetupDiDestroyDeviceInfoList(device_list);
}
It's very similar to what you wrote, except that mine uses GUID_DEVINTERFACE_COMPORT to find only serial ports.

Why does PIP_ADAPTER_INFO->LeaseExpires contain a different value after each call to GetAdaptersInfo

I am trying to create a program that achieves the same functionality as running the command ipconfg /all in Windows. I have managed to implement pretty much all the functionality however I am having difficulty getting the correct date and time for when the lease will expire. I am attempting to get this information by calling GetAdapterInfo and getting the value of LeaseExpires from the PIP_ADAPTER_INFO object that is returned. However not only does the value for lease expires not match that shown by ipconfig /all but it also changes on every run of the program. Can anyone spot why this would be happening?
#include <WinSock2.h>
#include <iphlpapi.h>
#include <stdio.h>
#pragma comment(lib, "Iphlpapi.lib")
PIP_ADAPTER_INFO getAdaptersInfo();
void outputFormatedTime(time_t * ttp);
int main()
{
PIP_ADAPTER_INFO pai = getAdaptersInfo();
if (pai)
{
for (; pai != NULL; pai = pai->Next)
{
if (pai->DhcpEnabled && pai->LeaseObtained)
{
printf("Lease Obtained: %llu - ", pai->LeaseObtained);
outputFormatedTime(&pai->LeaseObtained);
printf("Lease Expires: %llu - ", pai->LeaseExpires);
outputFormatedTime(&pai->LeaseExpires);
}
}
HeapFree(GetProcessHeap(), 0, pai);
pai = NULL;
}
return 0;
}
PIP_ADAPTER_INFO getAdaptersInfo()
{
PIP_ADAPTER_INFO paiResult;
ULONG ulOutputBufferLength = sizeof(IP_ADAPTER_INFO);
paiResult = (IP_ADAPTER_INFO *)HeapAlloc(GetProcessHeap(), 0, sizeof(IP_ADAPTER_INFO));
if (paiResult == NULL)
{
printf("Error allocating memory needed to call GetAdaptersInfo\n");
return paiResult;
}
if (GetAdaptersInfo(paiResult, &ulOutputBufferLength) == ERROR_BUFFER_OVERFLOW)
{
HeapFree(GetProcessHeap(), 0, paiResult);
paiResult = (IP_ADAPTER_INFO *)HeapAlloc(GetProcessHeap(), 0, ulOutputBufferLength);
if (paiResult == NULL)
{
printf("Error allocating memory needed to call GetAdaptersInfo\n");
return paiResult;
}
}
if (!GetAdaptersInfo(paiResult, &ulOutputBufferLength) == NO_ERROR)
{
printf("Error calling GetAdaptersInfo\n");
HeapFree(GetProcessHeap(), 0, paiResult);
paiResult = NULL;
return paiResult;
}
return paiResult;
}
void outputFormatedTime(time_t * ttp)
{
struct tm newtime;
char buffer[32];
errno_t error;
error = _localtime32_s(&newtime, (__time32_t *)ttp);
if (error)
{
printf("Invalid Argument to _localtime32_s\n");
}
else
{
error = asctime_s(buffer, 32, &newtime);
if (error)
{
printf("Invalid Argument to asctime_s\n");
}
else
{
printf("%s", buffer);
}
}
}

How to append "%.2X" data in char array or string in C (preferably) or C++?

I have been trying to fix it for last 3 days, and tried many options, but didn't get to work.
I have the following code in C++.
#include <winsock2.h>
#include <iphlpapi.h>
#include<stdio.h>
#include <stdlib.h>
#include <typeinfo>
#include <string>
// Link with Iphlpapi.lib
#pragma comment(lib, "IPHLPAPI.lib")
#define _CRT_SECURE_NO_WARNINGS
#define WORKING_BUFFER_SIZE 15000
#define MAX_TRIES 3
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
/* Note: could also use malloc() and free() */
int __cdecl main(int argc, char **argv)
{
/* Declare and initialize variables */
DWORD dwSize = 0;
DWORD dwRetVal = 0;
unsigned int i = 0;
// Set the flags to pass to GetAdaptersAddresses
ULONG flags = GAA_FLAG_INCLUDE_PREFIX;
// default to unspecified address family (both)
ULONG family = AF_UNSPEC;
LPVOID lpMsgBuf = NULL;
PIP_ADAPTER_ADDRESSES pAddresses = NULL;
ULONG outBufLen = 0;
ULONG Iterations = 0;
PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
PIP_ADAPTER_UNICAST_ADDRESS pUnicast = NULL;
PIP_ADAPTER_ANYCAST_ADDRESS pAnycast = NULL;
PIP_ADAPTER_MULTICAST_ADDRESS pMulticast = NULL;
IP_ADAPTER_DNS_SERVER_ADDRESS *pDnServer = NULL;
IP_ADAPTER_PREFIX *pPrefix = NULL;
// Allocate a 15 KB buffer to start with.
outBufLen = WORKING_BUFFER_SIZE;
std::string str;
char Buffer[255];
do {
pAddresses = (IP_ADAPTER_ADDRESSES *)MALLOC(outBufLen);
if (pAddresses == NULL) {
printf
("Memory allocation failed for IP_ADAPTER_ADDRESSES struct\n");
//exit(1);
}
dwRetVal =
GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen);
if (dwRetVal == ERROR_BUFFER_OVERFLOW) {
FREE(pAddresses);
pAddresses = NULL;
}
else {
break;
}
Iterations++;
} while ((dwRetVal == ERROR_BUFFER_OVERFLOW) && (Iterations < MAX_TRIES));
if (dwRetVal == NO_ERROR) {
// If successful, output some information from the data we received
pCurrAddresses = pAddresses;
while (pCurrAddresses) {
if (wcscmp(pCurrAddresses->FriendlyName, L"Ethernet") == 0) {
if (pCurrAddresses->PhysicalAddressLength != 0) {
printf("\tPhysical address: ");
for (i = 0; i < (int)pCurrAddresses- >PhysicalAddressLength;
i++) {
if (i == (pCurrAddresses->PhysicalAddressLength - 1)) {
printf("%.2X\n", (int)pCurrAddresses- >PhysicalAddress[i]);
//str.append(pCurrAddresses- >PhysicalAddress[i]);
// str += (int)pCurrAddresses- >PhysicalAddress[i];
//sprintf(Buffer + strlen(Buffer), "%.2X", (int)pCurrAddresses->PhysicalAddress[i]);
}
else {
printf("%.2X-", (int)pCurrAddresses- >PhysicalAddress[i]);
//str.append(pCurrAddresses- >PhysicalAddress[i]);
//str += (int)pCurrAddresses- >PhysicalAddress[i];
}
}
}
}
pCurrAddresses = pCurrAddresses->Next;
}
}
else {
printf("Call to GetAdaptersAddresses failed with error: %d\n",
dwRetVal);
if (dwRetVal == ERROR_NO_DATA)
printf("\tNo addresses were found for the requested parameters\n");
else {
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, dwRetVal, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
// Default language
(LPTSTR)& lpMsgBuf, 0, NULL)) {
printf("\tError: %s", lpMsgBuf);
LocalFree(lpMsgBuf);
if (pAddresses)
FREE(pAddresses);
//exit(1);
}
}
}
if (pAddresses) {
FREE(pAddresses);
}
MessageBoxA(NULL, str.c_str(), "testx", MB_OK);
system("pause");
return 0;
}
I want to print the mac address in MessageBox (winapi) using type LPCSTR at once, not in the loop, as it is happening now with printf().
I then have to send the mac address in URL using InternetOpenUrl() which has the data type of LPCSTR or LPWCSTR, I'll do the rest, once I succeed in printing and storing mac address in MessageBox and LPCSTR format respectively.
EDIT: My question is:
1. How to append the value of mac address into char array or string in loop?
2. How to store the mac address in LPCSTR to display in MessageBox()?
char MAC[18] = {0};
if (pCurrAddresses->PhysicalAddressLength != 0) {
// a MAC is usually 6 bytes in size...
sprintf(MAC, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
pCurrAddresses->PhysicalAddress[0],
pCurrAddresses->PhysicalAddress[1],
pCurrAddresses->PhysicalAddress[2],
pCurrAddresses->PhysicalAddress[3],
pCurrAddresses->PhysicalAddress[4],
pCurrAddresses->PhysicalAddress[5]);
printf("\tPhysical address: %s\n", MAC);
str.append(MAC);
}
If you want to be "politically correct" then format the actual number of bytes reported by PhysicalAddressLength (which can technically be as high as 8):
char MAC[24] = {0};
if (pCurrAddresses->PhysicalAddressLength != 0) {
char fmt[] = "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X:%.2X:%.2X";
if (pCurrAddresses->PhysicalAddressLength < 8)
fmt[(pCurrAddresses->PhysicalAddressLength * 5)-1] = 0;
sprintf(MAC, fmt,
pCurrAddresses->PhysicalAddress[0],
pCurrAddresses->PhysicalAddress[1],
pCurrAddresses->PhysicalAddress[2],
pCurrAddresses->PhysicalAddress[3],
pCurrAddresses->PhysicalAddress[4],
pCurrAddresses->PhysicalAddress[5]
pCurrAddresses->PhysicalAddress[6],
pCurrAddresses->PhysicalAddress[7]);
printf("\tPhysical address: %s\n", MAC);
str.append(MAC);
}

Native Wifi Api C++.Off/on wifi

I want write program for on/off wifi modules on C++ NativeWifi.
I received All modules.Then I do not know what to do.I have no experience in NativeWifi Api.Please help me, thank.
HANDLE hClient = NULL;
DWORD dwMaxClient = 2; //
DWORD dwCurVersion = 0;
DWORD dwResult = 0;
DWORD dwRetVal = 0;
int iRet = 0;
WCHAR GuidString[39] = { 0 };
unsigned int i, j, k;
/* variables used for WlanEnumInterfaces */
PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
PWLAN_INTERFACE_INFO pIfInfo = NULL;
PWLAN_AVAILABLE_NETWORK_LIST pBssList = NULL;
PWLAN_AVAILABLE_NETWORK pBssEntry = NULL;
dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
if (dwResult != ERROR_SUCCESS) {
wprintf(L"WlanOpenHandle failed with error: %u\n", dwResult);
return 1;
// You can use FormatMessage here to find out why the function failed
}
dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
if (dwResult != ERROR_SUCCESS) {
wprintf(L"WlanEnumInterfaces failed with error: %u\n", dwResult);
return 1;
// You can use FormatMessage here to find out why the function failed
}
else {
wprintf(L"Num Entries: %lu\n", pIfList->dwNumberOfItems);
wprintf(L"Current Index: %lu\n", pIfList->dwIndex);
for (i = 0; i < (int)pIfList->dwNumberOfItems; i++) {
pIfInfo = (WLAN_INTERFACE_INFO *)&pIfList->InterfaceInfo[i];
wprintf(L" Interface Index[%u]:\t %lu\n", i, i);
iRet = StringFromGUID2(pIfInfo->InterfaceGuid, (LPOLESTR)&GuidString,
sizeof(GuidString) / sizeof(*GuidString));
// For c rather than C++ source code, the above line needs to be
// iRet = StringFromGUID2(&pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString,
// sizeof(GuidString)/sizeof(*GuidString));
if (iRet == 0)
wprintf(L"StringFromGUID2 failed\n");
else {
wprintf(L" InterfaceGUID[%d]: %ws\n", i, GuidString);
}
}
}
I received All modules.Next, The radio state of a PHY is off if either dot11SoftwareRadioState or dot11HardwareRadioState member of the WLAN_PHY_RADIO_STATE structure is dot11_radio_state_off.
As the documentation of WLAN_PHY_RADIO_STATE states, you can use WlanSetInterface to turn the software radio state off.