27 april 2009

Obtain IPAddress in C# .NET 2.0

public static String getIPAddress()
{
foreach (IPAddress testIP in Dns.GetHostEntry(getComputername()).AddressList) {
return testIP.ToString();
}
}

Check for bit in byte

bool inByte(byte a, byte b) {
if ((a | b) == b) {
return true;
}
return false;
}

Read windows registry in c++

DWORD readReg(HKEY myKey, char* path, char* value) {
struct HKEY__* reghandle;
DWORD readValue;
DWORD size = 8192;
if (RegOpenKeyEx(myKey,path,0,KEY_READ,&reghandle) != ERROR_SUCCESS)
{
printf("Couldn't read key.");
}
DWORD ret;
ret = RegQueryValueEx(reghandle, value, NULL, NULL, (LPBYTE)&readValue, &size);
if (ret != ERROR_SUCCESS)
{
printf("Couldn't get value.");
}
RegCloseKey(reghandle);
return readValue;
}