Solved

RegEnumValue returns Invalid Parameter

Posted on 1997-08-29
13
808 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
13 Comments
 
LVL 3

Expert Comment

by:wolfcrag
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 3

Expert Comment

by:wolfcrag
Comment Utility
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
Comment Utility
Please post your declarations for the functions, so I can check them.
0
 
LVL 2

Author Comment

by:DavidMartin
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 3

Expert Comment

by:wolfcrag
Comment Utility
What are you setting IType to?
0
 
LVL 2

Author Comment

by:DavidMartin
Comment Utility
lType is declared as long
0
 
LVL 3

Expert Comment

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

Author Comment

by:DavidMartin
Comment Utility
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
Comment Utility
BTW.

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

Accepted Solution

by:
kfe earned 100 total points
Comment Utility
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
Comment Utility
Thanks KFE
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now