It is currently April 18th, 2024, 11:42 am

Multiple Network Adapter on same skin

Get help with creating, editing & fixing problems with skins
aetasoul
Posts: 11
Joined: August 7th, 2021, 6:49 am

Re: Multiple Network Adapter on same skin

Post by aetasoul »

SilverAzide wrote: August 9th, 2021, 2:45 pm So, has your original issue been resolved?
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 :confused:

Thank you all for the help!
1.png
2.png
3.png
You do not have the required permissions to view the files attached to this post.
aetasoul
Posts: 11
Joined: August 7th, 2021, 6:49 am

Re: Multiple Network Adapter on same skin

Post by aetasoul »

aetasoul wrote: August 16th, 2021, 6:59 am 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 :confused:

Thank you all for the help!

1.png

2.png

3.png
I used the wrong skin :Whistle

The problem is not solved, but i have found how to fix it (maybe? :oops: ). I think there is a problem with the SysInfo Plugin.

Setting the Sysinfodata with the name of the network adapter it try to find the adapter number by the name https://github.com/rainmeter/rainmeter/blob/master/Plugins/PluginSysInfo/SysInfo.cpp#L818

Editing the function as follow, the problem is fixed:

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;
}
Here the test application:

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;
}
GetAdaptersInfo example reference https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getadaptersinfo#examples


Pull request on Github: https://github.com/rainmeter/rainmeter/pull/270