BUG: "Out of memory" error if you sse the GetSetting function to retrieve an empty string from the registry in Visual Basic .NET and in Visual Basic 6.0 (814606)



The information in this article applies to:

  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0

SYMPTOMS

If you store an empty string in the registry by using the SaveSetting function in Microsoft Visual Basic .NET, and then you retrieve the same empty string value by using the GetSetting function in Microsoft Visual Basic 6.0, you may receive the following error message:
Run-time error '7': Out of memory

CAUSE

The SaveSetting function creates a registry key with the value provided as a parameter. The Visual Basic .NET SaveSetting function writes a value of zero bytes in the registry to represent an empty string. However, the Visual Basic 6.0 SaveSetting function or Registry Editor stores a two-byte NULL character in the registry for the empty string. The Visual Basic 6.0 GetSetting function also expects a two-byte NULL character for the empty string value. An error occurs while the application reads the string value from the registry, because the Visual Basic 6.0 GetSetting function receives zero-byte data instead of a two-byte NULL character.

WORKAROUND

To work around this problem, pass a vbNullChar as a parameter for the key value to the Visual Basic .NET SaveSetting function, instead of passing an empty string.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Open Microsoft Visual Studio .NET.
  2. On the File menu, point to Open, and then click Project.
  3. Under Project Types, select Visual Basic Projects.
  4. Under Templates, select Console Application.
  5. Name the project TestSaveSetting.
  6. Replace the code in the Module1.vb file with the following code:
    Module Module1
       Sub Main()
          'Save the empty string in registry
          SaveSetting("myAppName", "mySection", "myKey", "")
          Dim testString As String
    
          'Retrieve the empty string from registry
          testString = GetSetting("myAppName", "mySection", "myKey")
          Console.WriteLine("Retrieved Registry string value successfully")
       End Sub
    End Module
  7. On the Debug menu, click Start to run the application.

    The application creates the registry entry by using the SaveSetting function of Visual Basic .NET.
  8. Open Visual Basic 6.0.
  9. On the File menu, click New Project.
  10. In the New Project window, select Standard Exe, and then click OK.

    By default, Form1 is created.
  11. In the toolbox, double-click CommandButton.
  12. On Form, double-click Command1, and then add the following code to Command1_Click event:
    Dim strTest As String
    strTest = GetSetting("myAppName", "mySection", "myKey")
  13. On the Run menu, click Start to run the application.
  14. Click Command1.

Modification Type:MinorLast Reviewed:2/3/2006
Keywords:kbvs2005swept kbvs2005doesnotapply kbvs2002sp1sweep kbRegistry kbMigration kbString kbbug KB814606 kbAudDeveloper