Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

RegEnumValue returns Invalid Parameter

Posted on 1997-08-29
13
Medium Priority
?
890 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
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
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!

 
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 200 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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

578 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