RegEnumValue returns Invalid Parameter

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)
LVL 2
DavidMartinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wolfcragCommented:
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
DavidMartinAuthor 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!  
0
wolfcragCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

wolfcragCommented:
Errrm, I don't know what the above comment is doing there, must be some server error. In any case, ignore it.
0
y96andhaCommented:
Please post your declarations for the functions, so I can check them.
0
DavidMartinAuthor 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

0
wolfcragCommented:
What are you setting IType to?
0
DavidMartinAuthor Commented:
lType is declared as long
0
wolfcragCommented:
No, I meant its value. Have you initialised it to REG_BINARY?
0
DavidMartinAuthor 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)
0
DavidMartinAuthor Commented:
BTW.

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

Is that  the correct answer?

Do I get the points??!!

kfe
!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DavidMartinAuthor Commented:
Thanks KFE
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.