Hi,
I don't know the reason but windows broke my adapters, I had to disable all of them and re-enable one by one, after that the rainmeter skin works fine
Thank you all for the help!
Hi,
I used the wrong skin
Code: Select all
int GetBestInterfaceOrByName(LPCWSTR data, bool& found)
{
int index = 0;
if (_wcsicmp(data, L"BEST") == 0)
{
DWORD dwBestIndex;
if (NO_ERROR == GetBestInterface(INADDR_ANY, &dwBestIndex))
{
index = (int)dwBestIndex;
found = true;
}
}
else
{
PIP_ADAPTER_INFO pAdapterInfo;
ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
pAdapterInfo = (IP_ADAPTER_INFO*)MALLOC(sizeof(IP_ADAPTER_INFO));
if (pAdapterInfo == NULL) {
printf("Error allocating memory needed to call GetAdaptersinfo\n");
return 1;
}
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
FREE(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO*)MALLOC(ulOutBufLen);
if (pAdapterInfo == NULL) {
printf("Error allocating memory needed to call GetAdaptersinfo\n");
return 1;
}
}
if (ERROR_SUCCESS == GetAdaptersInfo(pAdapterInfo, &ulOutBufLen))
{
PIP_ADAPTER_INFO info = pAdapterInfo;
int i = 0;
while (info)
{
if (_wcsicmp(data, Widen(info->Description, -1, CP_ACP).c_str()) == 0)
{
index = info->Index;
found = true;
break;
}
info = info->Next;
++i;
}
}
}
return index;
}
Code: Select all
#include <winsock2.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;
#pragma comment(lib, "IPHLPAPI.lib")
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
/* Note: could also use malloc() and free() */
std::wstring Widen(const char* str, int strLen, int cp)
{
std::wstring wideStr;
if (str && *str)
{
if (strLen == -1)
{
strLen = (int)strlen(str);
}
int bufLen = MultiByteToWideChar(cp, 0, str, strLen, nullptr, 0);
if (bufLen > 0)
{
wideStr.resize(bufLen);
MultiByteToWideChar(cp, 0, str, strLen, &wideStr[0], bufLen);
}
}
return wideStr;
}
int GetBestInterfaceOrByName(LPCWSTR data, bool& found)
{
int index = 0;
if (_wcsicmp(data, L"BEST") == 0)
{
DWORD dwBestIndex;
if (NO_ERROR == GetBestInterface(INADDR_ANY, &dwBestIndex))
{
index = (int)dwBestIndex;
found = true;
}
}
else
{
PIP_ADAPTER_INFO pAdapterInfo;
ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
pAdapterInfo = (IP_ADAPTER_INFO*)MALLOC(sizeof(IP_ADAPTER_INFO));
if (pAdapterInfo == NULL) {
printf("Error allocating memory needed to call GetAdaptersinfo\n");
return 1;
}
// Make an initial call to GetAdaptersInfo to get
// the necessary size into the ulOutBufLen variable
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
FREE(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO*)MALLOC(ulOutBufLen);
if (pAdapterInfo == NULL) {
printf("Error allocating memory needed to call GetAdaptersinfo\n");
return 1;
}
}
if (ERROR_SUCCESS == GetAdaptersInfo(pAdapterInfo, &ulOutBufLen))
{
PIP_ADAPTER_INFO info = pAdapterInfo;
int i = 0;
while (info)
{
if (_wcsicmp(data, Widen(info->Description, -1, CP_ACP).c_str()) == 0)
{
index = info->Index;
found = true;
break;
}
info = info->Next;
++i;
}
}
}
return index;
}
int __cdecl main()
{
//Change this string to test
std::wstring siData = L"BEST";
bool notTrue = false;
int a = GetBestInterfaceOrByName(siData.c_str(), notTrue);
cout << "Adapter number: " << a;
}