Check Compact Framework version in registry

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • INTPnerd
    New Member
    • Jan 2008
    • 1

    #1

    Check Compact Framework version in registry

    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;
    }
    }
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    You are using a compact framework app to check the version of compact framework?

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by INTPnerd
      ... This is designed to run on Compact Framework 1...s
      Shouldn't the program just give Compact Framework 1 as the answer then?

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Code:
        \windows\cgacutil.exe
        That command pops up a window to tell you what version of CF you have running. Although it requires that you not be headless, and it doesn't help you at runtime.

        Comment

        Working...