Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than advapi32, prefix the name with the module name and a period.
RegGetValue (advapi32)
.
C# Signature:
/* Retrieves the type and data for the specified registry value. */
[DllImport("Advapi32.dll", EntryPoint = "RegGetValueW", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern LONG RegGetValue(
SafeRegistryHandle hkey,
string lpSubKey,
string lpValue,
EnumLib.RFlags dwFlags,
out EnumLib.RType pdwType,
IntPtr pvData,
ref DWORD pcbData);
/* Retrieves the type and data for the specified registry value. */
[DllImport("Advapi32.dll", EntryPoint = "RegGetValueW", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern LONG RegGetValue(
EnumLib.HKEY hkey,
string lpSubKey,
string lpValue,
EnumLib.RFlags dwFlags,
out EnumLib.RType pdwType,
IntPtr pvData,
ref DWORD pcbData);
[DllImport("advapi32.dll", SetLastError=true)]
static extern long RegGetValue(
IntPtr hkey,
string lpSubKey,
string lpValue,
uint dwFlags,
out IntPtr pdwType,
out IntPtr pvData,
IntPtr pcbData);
VB Signature:
Declare Function RegGetValue Lib "advapi32.dll" (TODO) As TODO
User-Defined Types:
/// <summary>
/// http://msdn.microsoft.com/en-us/library/windows/desktop/ms724884(v=vs.85).aspx
/// </summary>
internal enum RFlags
{
/// <summary>
/// Any
/// </summary>
Any = 65535,
None.
/// <summary>
/// No defined value type.
/// </summary>
RegNone = 1,
/// <summary>
/// A null-terminated string.
/// This will be either a Unicode or an ANSI string,
/// depending on whether you use the Unicode or ANSI functions.
/// </summary>
RegSz = 2,
/// <summary>
/// A sequence of null-terminated strings, terminated by an empty string (\0).
/// The following is an example:
/// String1\0String2\0String3\0LastString\0\0
/// The first \0 terminates the first string, the second to the last \0 terminates the last string,
/// and the final \0 terminates the sequence. Note that the final terminator must be factored into the length of the string.
/// </summary>
RegMultiSz = 32,
Microsoft.Win32.Registry.GetValue()
/// <summary>
/// A null-terminated string that contains unexpanded references to environment variables (for example, "%PATH%").
/// It will be a Unicode or ANSI string depending on whether you use the Unicode or ANSI functions.
/// To expand the environment variable references, use the ExpandEnvironmentStrings function.
/// </summary>
RegExpandSz = 4,
uint pcbData = 0;
EnumLib.RType type;
var pvData = IntPtr.Zero;
Api.advapi32.RegGetValue(
EnumLib.HKEY.HKEY_CURRENT_USER,
@"Software\LG Electronics\LG PC Suite IV\1.0", @"DS_URL",
EnumLib.RFlags.Any,
out type, pvData, ref pcbData);
pvData = pvData.Reallocate(pcbData);
Api.advapi32.RegGetValue(
EnumLib.HKEY.HKEY_CURRENT_USER,
@"Software\LG Electronics\LG PC Suite IV\1.0", @"DS_URL",
type.ToFlag(),
out type, pvData, ref pcbData);
if (type == EnumLib.RType.RegSz)
Console.WriteLine(pvData.ToUnicodeStr());
Alternative Managed API:
Microsoft.Win32.Registry.GetValue()
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).