mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
SysInfo.dll: Fixed messed up retrun value in some cases
This commit is contained in:
parent
51cddb00f8
commit
1eb8e1b46a
@ -220,42 +220,43 @@ PLUGIN_EXPORT LPCWSTR GetString(void* data)
|
|||||||
{
|
{
|
||||||
MeasureData* measure = (MeasureData*)data;
|
MeasureData* measure = (MeasureData*)data;
|
||||||
|
|
||||||
static WCHAR buffer[4096];
|
static WCHAR sBuffer[256];
|
||||||
DWORD len = 4095;
|
DWORD sBufferLen = _countof(sBuffer);
|
||||||
|
|
||||||
|
BYTE tmpBuffer[7168];
|
||||||
|
ULONG tmpBufferLen = _countof(tmpBuffer);
|
||||||
|
|
||||||
auto convertToWide = [&](LPCSTR str)->LPCWSTR
|
auto convertToWide = [&](LPCSTR str)->LPCWSTR
|
||||||
{
|
{
|
||||||
int strLen = (int)strlen(str);
|
MultiByteToWideChar(CP_ACP, 0, str, -1, sBuffer, 256);
|
||||||
int bufLen = MultiByteToWideChar(CP_ACP, 0, str, strLen, NULL, 0);
|
return sBuffer;
|
||||||
MultiByteToWideChar(CP_ACP, 0, str, strLen, buffer, min(bufLen, 4095));
|
|
||||||
return buffer;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (measure->type)
|
switch (measure->type)
|
||||||
{
|
{
|
||||||
case MEASURE_COMPUTER_NAME:
|
case MEASURE_COMPUTER_NAME:
|
||||||
GetComputerName(buffer, &len);
|
GetComputerName(sBuffer, &sBufferLen);
|
||||||
return buffer;
|
return sBuffer;
|
||||||
|
|
||||||
case MEASURE_USER_NAME:
|
case MEASURE_USER_NAME:
|
||||||
GetUserName(buffer, &len);
|
GetUserName(sBuffer, &sBufferLen);
|
||||||
return buffer;
|
return sBuffer;
|
||||||
|
|
||||||
case MEASURE_WORK_AREA:
|
case MEASURE_WORK_AREA:
|
||||||
wsprintf(buffer, L"%i x %i", GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN));
|
wsprintf(sBuffer, L"%i x %i", GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN));
|
||||||
return buffer;
|
return sBuffer;
|
||||||
|
|
||||||
case MEASURE_SCREEN_SIZE:
|
case MEASURE_SCREEN_SIZE:
|
||||||
wsprintf(buffer, L"%i x %i", GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
|
wsprintf(sBuffer, L"%i x %i", GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
|
||||||
return buffer;
|
return sBuffer;
|
||||||
|
|
||||||
case MEASURE_OS_VERSION:
|
case MEASURE_OS_VERSION:
|
||||||
return GetPlatformName();
|
return GetPlatformName();
|
||||||
|
|
||||||
case MEASURE_ADAPTER_DESCRIPTION:
|
case MEASURE_ADAPTER_DESCRIPTION:
|
||||||
if (ERROR_SUCCESS == GetAdaptersInfo((IP_ADAPTER_INFO*)buffer, &len))
|
if (ERROR_SUCCESS == GetAdaptersInfo((IP_ADAPTER_INFO*)tmpBuffer, &tmpBufferLen))
|
||||||
{
|
{
|
||||||
PIP_ADAPTER_INFO info = (IP_ADAPTER_INFO*)buffer;
|
PIP_ADAPTER_INFO info = (IP_ADAPTER_INFO*)tmpBuffer;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (info)
|
while (info)
|
||||||
{
|
{
|
||||||
@ -271,9 +272,9 @@ PLUGIN_EXPORT LPCWSTR GetString(void* data)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MEASURE_IP_ADDRESS:
|
case MEASURE_IP_ADDRESS:
|
||||||
if (NO_ERROR == GetIpAddrTable((PMIB_IPADDRTABLE)buffer, &len, FALSE))
|
if (NO_ERROR == GetIpAddrTable((PMIB_IPADDRTABLE)tmpBuffer, &tmpBufferLen, FALSE))
|
||||||
{
|
{
|
||||||
PMIB_IPADDRTABLE ipTable = (PMIB_IPADDRTABLE)buffer;
|
PMIB_IPADDRTABLE ipTable = (PMIB_IPADDRTABLE)tmpBuffer;
|
||||||
if (measure->data >= 1000)
|
if (measure->data >= 1000)
|
||||||
{
|
{
|
||||||
measure->data = measure->data - 999;
|
measure->data = measure->data - 999;
|
||||||
@ -284,37 +285,37 @@ PLUGIN_EXPORT LPCWSTR GetString(void* data)
|
|||||||
if (measure->data == 0)
|
if (measure->data == 0)
|
||||||
{
|
{
|
||||||
DWORD ip = ipTable->table[i].dwAddr;
|
DWORD ip = ipTable->table[i].dwAddr;
|
||||||
wsprintf(buffer, L"%i.%i.%i.%i", ip % 256, (ip >> 8) % 256, (ip >> 16) % 256, (ip >> 24) % 256);
|
wsprintf(sBuffer, L"%i.%i.%i.%i", ip % 256, (ip >> 8) % 256, (ip >> 16) % 256, (ip >> 24) % 256);
|
||||||
return buffer;
|
return sBuffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (measure->data < ipTable->dwNumEntries)
|
else if (measure->data < ipTable->dwNumEntries)
|
||||||
{
|
{
|
||||||
DWORD ip = ipTable->table[measure->data].dwAddr;
|
DWORD ip = ipTable->table[measure->data].dwAddr;
|
||||||
wsprintf(buffer, L"%i.%i.%i.%i", ip % 256, (ip >> 8) % 256, (ip >> 16) % 256, (ip >> 24) % 256);
|
wsprintf(sBuffer, L"%i.%i.%i.%i", ip % 256, (ip >> 8) % 256, (ip >> 16) % 256, (ip >> 24) % 256);
|
||||||
return buffer;
|
return sBuffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return L"";
|
return L"";
|
||||||
|
|
||||||
case MEASURE_NET_MASK:
|
case MEASURE_NET_MASK:
|
||||||
if (NO_ERROR == GetIpAddrTable((PMIB_IPADDRTABLE)buffer, &len, FALSE))
|
if (NO_ERROR == GetIpAddrTable((PMIB_IPADDRTABLE)tmpBuffer, &tmpBufferLen, FALSE))
|
||||||
{
|
{
|
||||||
PMIB_IPADDRTABLE ipTable = (PMIB_IPADDRTABLE)buffer;
|
PMIB_IPADDRTABLE ipTable = (PMIB_IPADDRTABLE)tmpBuffer;
|
||||||
if (measure->data < ipTable->dwNumEntries)
|
if (measure->data < ipTable->dwNumEntries)
|
||||||
{
|
{
|
||||||
DWORD ip = ipTable->table[measure->data].dwMask;
|
DWORD ip = ipTable->table[measure->data].dwMask;
|
||||||
wsprintf(buffer, L"%i.%i.%i.%i", ip % 256, (ip >> 8) % 256, (ip >> 16) % 256, (ip >> 24) % 256);
|
wsprintf(sBuffer, L"%i.%i.%i.%i", ip % 256, (ip >> 8) % 256, (ip >> 16) % 256, (ip >> 24) % 256);
|
||||||
return buffer;
|
return sBuffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MEASURE_GATEWAY_ADDRESS:
|
case MEASURE_GATEWAY_ADDRESS:
|
||||||
if (ERROR_SUCCESS == GetAdaptersInfo((IP_ADAPTER_INFO*)buffer, &len))
|
if (ERROR_SUCCESS == GetAdaptersInfo((IP_ADAPTER_INFO*)tmpBuffer, &tmpBufferLen))
|
||||||
{
|
{
|
||||||
PIP_ADAPTER_INFO info = (IP_ADAPTER_INFO*)buffer;
|
PIP_ADAPTER_INFO info = (IP_ADAPTER_INFO*)tmpBuffer;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (info)
|
while (info)
|
||||||
{
|
{
|
||||||
@ -329,25 +330,25 @@ PLUGIN_EXPORT LPCWSTR GetString(void* data)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MEASURE_HOST_NAME:
|
case MEASURE_HOST_NAME:
|
||||||
if (ERROR_SUCCESS == GetNetworkParams((PFIXED_INFO)buffer, &len))
|
if (ERROR_SUCCESS == GetNetworkParams((PFIXED_INFO)tmpBuffer, &tmpBufferLen))
|
||||||
{
|
{
|
||||||
PFIXED_INFO info = (PFIXED_INFO)buffer;
|
PFIXED_INFO info = (PFIXED_INFO)tmpBuffer;
|
||||||
return convertToWide(info->HostName);
|
return convertToWide(info->HostName);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MEASURE_DOMAIN_NAME:
|
case MEASURE_DOMAIN_NAME:
|
||||||
if (ERROR_SUCCESS == GetNetworkParams((PFIXED_INFO)buffer, &len))
|
if (ERROR_SUCCESS == GetNetworkParams((PFIXED_INFO)tmpBuffer, &tmpBufferLen))
|
||||||
{
|
{
|
||||||
PFIXED_INFO info = (PFIXED_INFO)buffer;
|
PFIXED_INFO info = (PFIXED_INFO)tmpBuffer;
|
||||||
return convertToWide(info->DomainName);
|
return convertToWide(info->DomainName);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MEASURE_DNS_SERVER:
|
case MEASURE_DNS_SERVER:
|
||||||
if (ERROR_SUCCESS == GetNetworkParams((PFIXED_INFO)buffer, &len))
|
if (ERROR_SUCCESS == GetNetworkParams((PFIXED_INFO)tmpBuffer, &tmpBufferLen))
|
||||||
{
|
{
|
||||||
PFIXED_INFO info = (PFIXED_INFO)buffer;
|
PFIXED_INFO info = (PFIXED_INFO)tmpBuffer;
|
||||||
if (info->CurrentDnsServer)
|
if (info->CurrentDnsServer)
|
||||||
{
|
{
|
||||||
return convertToWide(info->CurrentDnsServer->IpAddress.String);
|
return convertToWide(info->CurrentDnsServer->IpAddress.String);
|
||||||
|
Loading…
Reference in New Issue
Block a user