CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2006
    Posts
    134

    Registry can be read in debug, not in release

    Greetings!

    I am using VS 2008 on a Windows 7 64-bit operating system.

    I have written a helpful tool whose first step is to read a list of 32-bit ODBCs from the registry. In debug mode, it works fine. It reads the list from registry key "HKLM\Software\ODBC\ODBC.INI\ODBC Data Sources", and finds 17 of them. But when I build in release mode, the ODBC.INI key can be opened, but its ODBC Data Sources subkey cannot be opened. What's going on?

    I don't have a simple snippet I can show you yet. I'll throw together a little test program in a moment.

    I am running both versions by double-clicking on the exe file from Windows Explorer.

    RobR

  2. #2
    Join Date
    Aug 2006
    Posts
    134

    Re: Registry can be read in debug, not in release

    Here is sample code that demonstrates his behavior:

    Code:
            public System.Collections.SortedList GetSystemDataSourceNames()
            {
                System.Collections.SortedList dsnList = new System.Collections.SortedList();
    
    			try
    			{
    				// get system dsn's
    				Microsoft.Win32.RegistryKey reg = (Microsoft.Win32.Registry.LocalMachine).OpenSubKey("Software");
    				if (reg != null)
    				{
    					MessageBox.Show("Opened subkey " + reg.Name);
    					reg = reg.OpenSubKey("Wow6432Node");
    					//if (true)
    					if (reg != null)
    					{
    						MessageBox.Show("Opened Wow6432Node key.");
    						reg.Close();
    					}
    					else
    					{
    						MessageBox.Show("Failed to opened Wow6432Node key.");
    					}
    				}
    			}
    			catch (Exception ex)
    			{
    				MessageBox.Show("Exception when reading registry: " + ex.Message);
    			}
    
                return dsnList;
            }
    I built my application using this code in debug and release modes. In debug mode, it failed to open the Wow6432Node key. In release mode, it opened it. This is actually the opposite of my application, because my application was not opening the Wow key. Thus, it worked in debug mode and did not work in release mode.

    Why is the Wow6432 key handled differently in debug and release mode? Is there some way I can change that behavior?

    Thanks for your help!

    RobR

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured