mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 02:25:17 +00:00
Added new files for common functions.
svn path=/trunk/; revision=8179
This commit is contained in:
parent
3bf9107ff9
commit
2124442b3d
3 changed files with 123 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
||||||
# $Id: makefile,v 1.11 2004/01/11 20:46:06 navaraf Exp $
|
# $Id: makefile,v 1.12 2004/02/15 00:04:07 arty Exp $
|
||||||
|
|
||||||
PATH_TO_TOP = ../..
|
PATH_TO_TOP = ../..
|
||||||
|
|
||||||
|
@ -15,6 +15,12 @@ THREAD_OBJECTS = \
|
||||||
thread/exit.o \
|
thread/exit.o \
|
||||||
thread/stack.o
|
thread/stack.o
|
||||||
|
|
||||||
|
STRING_OBJECTS = \
|
||||||
|
string/append.o
|
||||||
|
|
||||||
|
REGISTRY_OBJECTS = \
|
||||||
|
registry/registry.o
|
||||||
|
|
||||||
MISC_OBJECTS = \
|
MISC_OBJECTS = \
|
||||||
misc/devmode.o \
|
misc/devmode.o \
|
||||||
misc/logfont.o \
|
misc/logfont.o \
|
||||||
|
@ -30,7 +36,8 @@ TARGET_NAME = rosrtl
|
||||||
|
|
||||||
TARGET_CFLAGS = -D__USE_W32API -Wall -Werror
|
TARGET_CFLAGS = -D__USE_W32API -Wall -Werror
|
||||||
|
|
||||||
TARGET_OBJECTS = $(THREAD_OBJECTS) $(MISC_OBJECTS)
|
TARGET_OBJECTS = $(THREAD_OBJECTS) $(MISC_OBJECTS) $(STRING_OBJECTS) \
|
||||||
|
$(REGISTRY_OBJECTS)
|
||||||
|
|
||||||
DEP_OBJECTS = $(TARGET_OBJECTS)
|
DEP_OBJECTS = $(TARGET_OBJECTS)
|
||||||
|
|
||||||
|
|
76
reactos/lib/rosrtl/registry/registry.c
Normal file
76
reactos/lib/rosrtl/registry/registry.c
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
#define NTOS_MODE_USER
|
||||||
|
#include <ntos.h>
|
||||||
|
#include <rosrtl/string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Utility function to read a value from the registry more easily.
|
||||||
|
*
|
||||||
|
* IN PUNICODE_STRING KeyName -> Name of key to open
|
||||||
|
* IN PUNICODE_STRING ValueName -> Name of value to open
|
||||||
|
* OUT PUNICODE_STRING ReturnedValue -> String contained in registry
|
||||||
|
*
|
||||||
|
* Returns NTSTATUS
|
||||||
|
*/
|
||||||
|
|
||||||
|
NTSTATUS NTAPI RosReadRegistryValue( PUNICODE_STRING KeyName,
|
||||||
|
PUNICODE_STRING ValueName,
|
||||||
|
PUNICODE_STRING ReturnedValue ) {
|
||||||
|
NTSTATUS Status;
|
||||||
|
HANDLE KeyHandle;
|
||||||
|
OBJECT_ATTRIBUTES KeyAttributes;
|
||||||
|
PKEY_VALUE_PARTIAL_INFORMATION KeyValuePartialInfo;
|
||||||
|
ULONG Length = 0;
|
||||||
|
ULONG ResLength = 0;
|
||||||
|
UNICODE_STRING Temp;
|
||||||
|
|
||||||
|
InitializeObjectAttributes(&KeyAttributes, KeyName, OBJ_CASE_INSENSITIVE,
|
||||||
|
NULL, NULL);
|
||||||
|
Status = ZwOpenKey(&KeyHandle, KEY_ALL_ACCESS, &KeyAttributes);
|
||||||
|
if( !NT_SUCCESS(Status) ) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = ZwQueryValueKey(KeyHandle, ValueName, KeyValuePartialInformation,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
&ResLength);
|
||||||
|
|
||||||
|
if( Status != STATUS_BUFFER_TOO_SMALL ) {
|
||||||
|
NtClose(KeyHandle);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResLength += sizeof( *KeyValuePartialInfo );
|
||||||
|
KeyValuePartialInfo =
|
||||||
|
RtlAllocateHeap(GetProcessHeap(), 0, ResLength);
|
||||||
|
Length = ResLength;
|
||||||
|
|
||||||
|
if( !KeyValuePartialInfo ) {
|
||||||
|
NtClose(KeyHandle);
|
||||||
|
return STATUS_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = ZwQueryValueKey(KeyHandle, ValueName, KeyValuePartialInformation,
|
||||||
|
(PVOID)KeyValuePartialInfo,
|
||||||
|
Length,
|
||||||
|
&ResLength);
|
||||||
|
|
||||||
|
if( !NT_SUCCESS(Status) ) {
|
||||||
|
NtClose(KeyHandle);
|
||||||
|
RtlFreeHeap(GetProcessHeap(),0,KeyValuePartialInfo);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
Temp.Length = Temp.MaximumLength = KeyValuePartialInfo->DataLength;
|
||||||
|
Temp.Buffer = (PWCHAR)KeyValuePartialInfo->Data;
|
||||||
|
|
||||||
|
/* At this point, KeyValuePartialInfo->Data contains the key data */
|
||||||
|
RtlInitUnicodeString(ReturnedValue,L"");
|
||||||
|
RosAppendUnicodeString(ReturnedValue,&Temp,FALSE);
|
||||||
|
|
||||||
|
RtlFreeHeap(GetProcessHeap(),0,KeyValuePartialInfo);
|
||||||
|
NtClose(KeyHandle);
|
||||||
|
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
38
reactos/lib/rosrtl/string/append.c
Normal file
38
reactos/lib/rosrtl/string/append.c
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#define NTOS_MODE_USER
|
||||||
|
#include <ntos.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Utility to copy and append two unicode strings.
|
||||||
|
*
|
||||||
|
* IN OUT PUNICODE_STRING ResultFirst -> First string and result
|
||||||
|
* IN PUNICODE_STRING Second -> Second string to append
|
||||||
|
* IN BOOL Deallocate -> TRUE: Deallocate First string before
|
||||||
|
* overwriting.
|
||||||
|
*
|
||||||
|
* Returns NTSTATUS.
|
||||||
|
*/
|
||||||
|
|
||||||
|
NTSTATUS NTAPI RosAppendUnicodeString(PUNICODE_STRING ResultFirst,
|
||||||
|
PUNICODE_STRING Second,
|
||||||
|
BOOL Deallocate) {
|
||||||
|
NTSTATUS Status;
|
||||||
|
PWSTR new_string =
|
||||||
|
RtlAllocateHeap(GetProcessHeap(),0,
|
||||||
|
(ResultFirst->Length + Second->Length + sizeof(WCHAR)));
|
||||||
|
if( !new_string ) {
|
||||||
|
return STATUS_NO_MEMORY;
|
||||||
|
}
|
||||||
|
memcpy( new_string, ResultFirst->Buffer,
|
||||||
|
ResultFirst->Length );
|
||||||
|
memcpy( new_string + ResultFirst->Length / sizeof(WCHAR),
|
||||||
|
Second->Buffer,
|
||||||
|
Second->Length );
|
||||||
|
if( Deallocate ) RtlFreeUnicodeString(ResultFirst);
|
||||||
|
ResultFirst->Length += Second->Length;
|
||||||
|
ResultFirst->MaximumLength = ResultFirst->Length;
|
||||||
|
new_string[ResultFirst->Length / sizeof(WCHAR)] = 0;
|
||||||
|
Status = RtlCreateUnicodeString(ResultFirst,new_string) ?
|
||||||
|
STATUS_SUCCESS : STATUS_NO_MEMORY;
|
||||||
|
RtlFreeHeap(GetProcessHeap(),0,new_string);
|
||||||
|
return Status;
|
||||||
|
}
|
Loading…
Reference in a new issue