在win98中通过,但是在win2000 中报错:
"0x796d347b"指令引用的"0x000000000"内存。该内存不能为"read"。----------------------------
Private Const HKEY_CURRENT_USER As Long = &H80000001
Private Const REG_SZ = 1
Private Declare Function RegCreateKey ......
Private Declare Function RegSetValueEx ......
Private Declare Function RegCloseKey ......
Private Declare Function RegOpenKey ......RegCreateKey HKEY_CURRENT_USER, "Software\Getnews", hKey
RegSetValueEx hKey, "user", 0, REG_SZ, ByVal str2, Len(str2) + 1  <<=====这里
RegSetValueEx hKey, "test", 0, REG_SZ, ByVal str1, Len(str1) + 1
RegCloseKey (hKey)
Unload Me如何解决???

解决方案 »

  1.   

    Len(str2) + 1取长度不对!可用
    LenB(StrConv(str2, vbFromUnicode))取得也可用API
    lstrlen(str2)
      

  2.   

    RegSetValueEx hKey, "user", 0, REG_SZ, ByVal str2, Len(str2) + 1  <<=====这里
    RegSetValueEx hKey, "test", 0, REG_SZ, ByVal str1, Len(str1) + 1
    -----------------------------------
    多了个ByVal关键字呀,去掉吧……
    RegSetValueEx hKey, "user", 0, REG_SZ, str2, Len(str2) + 1  '<<=====这里
    RegSetValueEx hKey, "test", 0, REG_SZ, str1, Len(str1) + 1
      

  3.   

    更正:
    RegSetValueEx hKey, "user", 0, REG_SZ, ByVal str2, Len(str2) + 1应该改为
    RegSetValueEx hKey, "user", 0, REG_SZ, ByVal str2, Len(str2)另外要确保str2不能为空 
    请参考以下微软的例子:
        ***********************************************
        ' Determine data type and use appropriate
        ' passed value.
        ' ***********************************************
        Select Case pDatatype
           Case REG_DWORD
              MyKeyValueLng = ValueToAdd
              lResult = RegSetValueEx(phkResult, KeyToAdd, _
                                      ByVal 0&, pDatatype, _
                                      MyKeyValueLng, Len(MyKeyValueLng))
           Case REG_SZ
              MyKeyValueStr = ValueToAdd
              lResult = RegSetValueEx(phkResult, KeyToAdd, _
                                      ByVal 0&, pDatatype, _
                                      ByVal MyKeyValueStr, Len(MyKeyValueStr))
        End Select
      

  4.   

    谢谢,问题解决!to: unsigned(僵哥)  去掉ByVal后,写进注册表的东西怪怪的,都是乱码