We help IT Professionals succeed at work.

RegEnumValue returns Invalid Parameter

DavidMartin
DavidMartin asked
on
Medium Priority
971 Views
Last Modified: 2012-08-13
I'm trying to use the RegEnumValue function but all I get as a return value is:

87 - ERROR_INVALID_PARAMETER

Has anyone got any Idea which parameter is wrong or managed to get this to work, I am trying to evalute a key that resides in the following path:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\

Here's  a snippet of the code i'm using :

lRetVal = RegOpenKeyEx(lRootKey, sSubKey, 0, KEY_ALL_ACCESS, hKey)   ' Open Registry Key

    sValueName = String(1024, " ")
    lValueNameLen = Len(sValueName)
    sData = String(1024, " ")
    lDataLen = Len(sData)
    lRetVal = RegEnumValue(hKey, 0, ByVal sValueName, lValueNameLen, 0, lType, ByVal btData, lDataLen)
Comment
Watch Question

Commented:
You should use the following declaration:

Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long

The key here is to set the second last parameter declaration from lpData As Byte to lpData As Any. Then your error should go away.




Author

Commented:
Nice try Wolfcrag, but I've already tried changing the function declaration as you have shown.  

I've also tried passing the parameter as a long and Nul but all return the same!  

Commented:
I tried out the code and got the same results as you. Weird is the only word I can use to describe this! The only workaround you have is to use the Picture object instead of using a compatible bitmap. Not the best solution, I agree.

Commented:
Errrm, I don't know what the above comment is doing there, must be some server error. In any case, ignore it.

Commented:
Please post your declarations for the functions, so I can check them.

Author

Commented:
These are the declares I have tried (note 2nd to last parameter is changing);

Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long


Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long

Commented:
What are you setting IType to?

Author

Commented:
lType is declared as long

Commented:
No, I meant its value. Have you initialised it to REG_BINARY?

Author

Commented:
I've solved it myself, do I get the Points?

Here's the solution:

Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long

    dim bValue as Bytle
   
    sValueName = String(1024, " ")
    lValueNameLen = Len(sValueName)
    sData = String(1024, " ")
    lDataLen = Len(sData)
   
    lRetVal = RegEnumValue(hKey, 0, sValueName, lValueNameLen, 0, lType, bData, lDataLen)

Author

Commented:
BTW.

lType is for returning values, not setting them...
Commented:
No, you don't get the points!

Is that  the correct answer?

Do I get the points??!!

kfe
!

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks KFE
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.