Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

regcreatekeyex (coredll)
 

coredll is for smart devices, not desktop Windows. Therefore, this information only applies to code using the .NET Compact Framework. To see if information for regcreatekeyex in other DLLs exists, click on Find References to the right.

.
Summary
Creates the specified key. If the key already exists in the registry, it is opened.

C# Signature:

[DllImport("coredll.dll")]
public static extern int RegCreateKeyEx(
   UIntPtr hKey, string lpSubKey, uint dwReserved, string lpClass,
   uint dwOptions, int samDesired, IntPtr lpSecurityAttributes,
   out IntPtr phkResult, out RegistryDispositionValue lpdwDisposition);

User-Defined Types:

[Flags]
enum RegistryDispositionValue : uint
{
   REG_CREATED_NEW_KEY     = 0x00000001,
   REG_OPENED_EXISTING_KEY = 0x00000002
}

Notes:

The .NET Compact Framework does not contain a HandleRef type, so it may be necessary to call GC.KeepAlive after calling this function if the calling class wraps the hKey parameter as an unmanaged resource.

Tips & Tricks:

C#:

public UIntPtr HKEY_CLASSES_ROOT = (UIntPtr)0x80000000;
public const int REG_OPTION_NON_VOLATILE = 0;
:::
int iResult;
IntPtr ipKey = IntPtr.Zero;
string strRegKeyPath;
int iDisposition;

iResult = RegCreateKeyEx(HKEY_CLASSES_ROOT, strRegKeyPath, 0,
   null, REG_OPTION_NON_VOLATILE, 0, IntPtr.Zero, out ipKey,
   out iDisposition);

// Z.F.Zeynal

public enum RootRegKeys : uint
    {
        HKEY_CLASSES_ROOT = 0x8000000,
        HKEY_CURRENT_USER = 0x80000001,
        HKEY_LOCAL_MACHINE = 0x80000002,
        HKEY_USERS = 0x80000003
    };

    public enum RegValueTypes
    {
        REG_DWORD = 4,
        REG_SZ = 1
    };
private uint CreateKey(RootRegKeys rrk, string Path)
        {
            uint nKey = 0;
            uint nDisposition =0;
            int rez = RegCreateKeyEx ((uint) rrk,Path,0,String.Empty,0,0,0,ref nKey,ref nDisposition);
            if (rez != 0) throw new Exception ("Can't create key");
            return nKey; //Key handle
        }


Alternative Managed API:

CF V2.0

Microsoft.Win32.Registry.LocalMachine.CreateSubKey(SubKey as string)

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions