Here is some code that is not working right for me. This is designed to run on Compact Framework 1, so I cannot just use the registry classes. Obviously GetInstalledVer sions() is incomplete as far as what it is returning , but the part that I can't figure out is the call to RegQueryValueEx , which returns a value of 2 instead 0. I already tried passing in an array of bytes instead of the StringBuilder but this did not fix it. The device I am testing this code on does have a registry entry here. I looked it up using a registry viewer. Any ideas?
Code:
public class CompactFrameworkVersionChecker
{
private const uint HKEY_LOCAL_MACHINE = 0x80000002;
[DllImport("coredll.dll", CharSet=CharSet.Unicode)]
private static extern uint RegOpenKeyEx(
uint HKEY,
string lpSubKey,
int ulOptions,
uint samDesired,
out uint phkResult);
[DllImport("coredll.dll", CharSet=CharSet.Unicode)]
private static extern uint RegQueryValueEx(
uint hKey,
string lpValueName,
int lpReserved,
ref int lpType,
StringBuilder lpData,
ref int lpcbData);
[DllImport("coredll.dll")]
private static extern int RegCloseKey(uint hkey);
public static string[] GetInstalledVersions()
{
uint key;
uint ret;
int lpType = new int();
StringBuilder lpData = new StringBuilder();
int lpcbData = lpData.Length;
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft", 0, 0, out key);
string[] installedVersions = new string[] { };
if (ret == 0)
{
ret = RegQueryValueEx(key, ".NETCompactFramework", 0, ref lpType, lpData, ref lpcbData);
if (ret == 0)
{
// success, your data in in lpData to be converted
installedVersions = new string[] { lpData.ToString() };
}
}
RegCloseKey(key);
return installedVersions;
}
}
Comment