create a new rigistry key

Hi,

i have tried to create a new key in the registry but the compiler dont let me succeed: It tells me always that the function RegCreateKeyEx() does not exist in the lib.

Can someone help me

Here is the code:

Declare Function RegCreateKeyEx Lib "Coredll.dll" Alias "RegCreateKeyExW" ( _

ByVal hkey As Long, _

ByVal lpSubKey As String, _

ByVal Reserved As Long, _

ByVal lpClass As String, _

ByVal dwOptions As Long, _

ByVal samDesired As Long, _

ByVal lpSecurityAttributes As Long, _

ByVal phkResult As Long, _

ByVal lpdwDisposition As Long) _

As Long

Public Function CreateNewKey(ByVal lSection As Long, _

ByVal sNewKeyName As String)

Dim hNewKey As Long '-- Handle to the new key

Dim lRetVal As Long '-- Result of the RegCreateKeyEx function

'-- Create Registry Key

'-- If key already exists, nothing happens

lRetVal = RegCreateKeyEx(lSection, sNewKeyName, 0, _

vbNullString, REG_OPTION_NON_VOLATILE, _

KEY_ALL_ACCESS, _

0, hNewKey, lRetVal)

'-- Return Handle to Key

CreateNewKey = hNewKey

'-- Close Registry Handle

RegCloseKey(hNewKey)

End Function



Answer this question

create a new rigistry key

  • DragonSpeed

    With a very quick glance I can tell you that those Longs should be Integers (and I won't check if anything else is wrong too).

    What you should do in CF v1.0 is use the OpenNETCF.Win32 namespace from the SDF. For CF v2.0, you should use Microsoft.Win32 which is there now out of the box. No point reinventing the wheel in either case.

    Cheers

    Daniel



  • create a new rigistry key