Solved

RegEnumValue returns Invalid Parameter

Posted on 1997-08-29
13
840 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)
0
Comment
Question by:DavidMartin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 3

Expert Comment

by:wolfcrag
ID: 1432778
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.




0
 
LVL 2

Author Comment

by:DavidMartin
ID: 1432779
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!  
0
 
LVL 3

Expert Comment

by:wolfcrag
ID: 1432780
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:wolfcrag
ID: 1432781
Errrm, I don't know what the above comment is doing there, must be some server error. In any case, ignore it.
0
 
LVL 5

Expert Comment

by:y96andha
ID: 1432782
Please post your declarations for the functions, so I can check them.
0
 
LVL 2

Author Comment

by:DavidMartin
ID: 1432783
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

0
 
LVL 3

Expert Comment

by:wolfcrag
ID: 1432784
What are you setting IType to?
0
 
LVL 2

Author Comment

by:DavidMartin
ID: 1432785
lType is declared as long
0
 
LVL 3

Expert Comment

by:wolfcrag
ID: 1432786
No, I meant its value. Have you initialised it to REG_BINARY?
0
 
LVL 2

Author Comment

by:DavidMartin
ID: 1432787
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)
0
 
LVL 2

Author Comment

by:DavidMartin
ID: 1432788
BTW.

lType is for returning values, not setting them...
0
 

Accepted Solution

by:
kfe earned 100 total points
ID: 1432789
No, you don't get the points!

Is that  the correct answer?

Do I get the points??!!

kfe
!
0
 
LVL 2

Author Comment

by:DavidMartin
ID: 1432790
Thanks KFE
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question