mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 04:43:21 +00:00
Fix bugs in IntLoadKeyboardLayout and make it work.
svn path=/trunk/; revision=25596
This commit is contained in:
parent
a00e6038e9
commit
f603122931
1 changed files with 60 additions and 54 deletions
|
@ -33,9 +33,6 @@
|
||||||
#include <wine/debug.h>
|
#include <wine/debug.h>
|
||||||
|
|
||||||
|
|
||||||
/* Directory to load key layouts from */
|
|
||||||
#define SYSTEMROOT_DIR L"\\SystemRoot\\System32\\"
|
|
||||||
|
|
||||||
/* GLOBALS *******************************************************************/
|
/* GLOBALS *******************************************************************/
|
||||||
|
|
||||||
typedef struct __TRACKINGLIST {
|
typedef struct __TRACKINGLIST {
|
||||||
|
@ -73,10 +70,11 @@ ReadRegistryValue( PUNICODE_STRING KeyName,
|
||||||
PKEY_VALUE_PARTIAL_INFORMATION KeyValuePartialInfo;
|
PKEY_VALUE_PARTIAL_INFORMATION KeyValuePartialInfo;
|
||||||
ULONG Length = 0;
|
ULONG Length = 0;
|
||||||
ULONG ResLength = 0;
|
ULONG ResLength = 0;
|
||||||
UNICODE_STRING Temp;
|
PWCHAR ReturnBuffer;
|
||||||
|
|
||||||
InitializeObjectAttributes(&KeyAttributes, KeyName, OBJ_CASE_INSENSITIVE,
|
InitializeObjectAttributes(&KeyAttributes, KeyName, OBJ_CASE_INSENSITIVE,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
|
|
||||||
Status = ZwOpenKey(&KeyHandle, KEY_ALL_ACCESS, &KeyAttributes);
|
Status = ZwOpenKey(&KeyHandle, KEY_ALL_ACCESS, &KeyAttributes);
|
||||||
if( !NT_SUCCESS(Status) )
|
if( !NT_SUCCESS(Status) )
|
||||||
{
|
{
|
||||||
|
@ -116,13 +114,18 @@ ReadRegistryValue( PUNICODE_STRING KeyName,
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
Temp.Length = Temp.MaximumLength = KeyValuePartialInfo->DataLength;
|
|
||||||
Temp.Buffer = (PWCHAR)KeyValuePartialInfo->Data;
|
|
||||||
|
|
||||||
/* At this point, KeyValuePartialInfo->Data contains the key data */
|
/* At this point, KeyValuePartialInfo->Data contains the key data */
|
||||||
RtlInitUnicodeString(ReturnedValue,L"");
|
ReturnBuffer = LocalAlloc(0, KeyValuePartialInfo->DataLength);
|
||||||
RtlAppendUnicodeStringToString(ReturnedValue,&Temp);
|
if(!ReturnBuffer)
|
||||||
|
{
|
||||||
|
NtClose(KeyHandle);
|
||||||
|
LocalFree(KeyValuePartialInfo);
|
||||||
|
return STATUS_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
RtlCopyMemory(ReturnBuffer, KeyValuePartialInfo->Data, KeyValuePartialInfo->DataLength);
|
||||||
|
RtlInitUnicodeString(ReturnedValue, ReturnBuffer);
|
||||||
|
|
||||||
LocalFree(KeyValuePartialInfo);
|
LocalFree(KeyValuePartialInfo);
|
||||||
NtClose(KeyHandle);
|
NtClose(KeyHandle);
|
||||||
|
|
||||||
|
@ -148,10 +151,12 @@ IntLoadKeyboardLayout( LPCWSTR pwszKLID,
|
||||||
UNICODE_STRING LayoutFile;
|
UNICODE_STRING LayoutFile;
|
||||||
UNICODE_STRING FullLayoutPath;
|
UNICODE_STRING FullLayoutPath;
|
||||||
LCID LocaleId;
|
LCID LocaleId;
|
||||||
PWCHAR KeyboardLayoutWSTR;
|
|
||||||
ULONG_PTR layout;
|
ULONG_PTR layout;
|
||||||
LANGID langid;
|
LANGID langid;
|
||||||
|
WCHAR FullPathBuffer[MAX_PATH];
|
||||||
|
WCHAR LayoutKeyNameBuffer[128] = L"\\REGISTRY\\Machine\\SYSTEM\\CurrentControlSet"
|
||||||
|
L"\\Control\\KeyboardLayouts\\";
|
||||||
|
|
||||||
layout = (ULONG_PTR) wcstoul(pwszKLID, NULL, 16);
|
layout = (ULONG_PTR) wcstoul(pwszKLID, NULL, 16);
|
||||||
|
|
||||||
// LocaleId = GetSystemDefaultLCID();
|
// LocaleId = GetSystemDefaultLCID();
|
||||||
|
@ -171,55 +176,59 @@ IntLoadKeyboardLayout( LPCWSTR pwszKLID,
|
||||||
else
|
else
|
||||||
layout |= layout << 16;
|
layout |= layout << 16;
|
||||||
|
|
||||||
DPRINT("Input = %S\n", pwszKLID );
|
DPRINT("Input = %S, DefaultLocale = %lx\n", pwszKLID, LocaleId );
|
||||||
|
|
||||||
DPRINT("DefaultLocale = %lx\n", LocaleId);
|
|
||||||
|
|
||||||
swprintf(LocaleBuffer, L"%08lx", LocaleId);
|
swprintf(LocaleBuffer, L"%08lx", LocaleId);
|
||||||
|
|
||||||
DPRINT("DefaultLocale = %S\n", LocaleBuffer);
|
DPRINT("DefaultLocale = %S\n", LocaleBuffer);
|
||||||
RtlInitUnicodeString(&DefaultLocale, LocaleBuffer);
|
RtlInitUnicodeString(&DefaultLocale, LocaleBuffer);
|
||||||
|
|
||||||
RtlInitUnicodeString(&LayoutKeyName,
|
RtlInitUnicodeString(&LayoutKeyName, LayoutKeyNameBuffer);
|
||||||
L"\\REGISTRY\\Machine\\SYSTEM\\CurrentControlSet"
|
LayoutKeyName.MaximumLength = sizeof(LayoutKeyNameBuffer);
|
||||||
L"\\Control\\KeyboardLayouts\\");
|
RtlAppendUnicodeStringToString(&LayoutKeyName, &DefaultLocale);
|
||||||
|
DPRINT("LayoutKeyName=%wZ\n", &LayoutKeyName);
|
||||||
RtlAppendUnicodeStringToString(&LayoutKeyName,&DefaultLocale);
|
RtlInitUnicodeString(&LayoutValueName, L"Layout File");
|
||||||
|
|
||||||
RtlInitUnicodeString(&LayoutValueName,L"Layout File");
|
|
||||||
|
|
||||||
Status = ReadRegistryValue(&LayoutKeyName,&LayoutValueName,&LayoutFile);
|
Status = ReadRegistryValue(&LayoutKeyName,&LayoutValueName,&LayoutFile);
|
||||||
|
|
||||||
RtlFreeUnicodeString(&LayoutKeyName);
|
|
||||||
|
|
||||||
DPRINT("Read registry and got %wZ\n", &LayoutFile);
|
if(!NT_SUCCESS(Status))
|
||||||
|
|
||||||
RtlInitUnicodeString(&FullLayoutPath,SYSTEMROOT_DIR);
|
|
||||||
RtlAppendUnicodeStringToString(&FullLayoutPath,&LayoutFile);
|
|
||||||
|
|
||||||
DPRINT("Loading Keyboard DLL %wZ\n", &FullLayoutPath);
|
|
||||||
|
|
||||||
RtlFreeUnicodeString(&LayoutFile);
|
|
||||||
|
|
||||||
KeyboardLayoutWSTR = LocalAlloc(LMEM_ZEROINIT,
|
|
||||||
FullLayoutPath.Length + sizeof(WCHAR));
|
|
||||||
|
|
||||||
if( !KeyboardLayoutWSTR )
|
|
||||||
{
|
{
|
||||||
DPRINT1("Couldn't allocate a string for the keyboard layout name.\n");
|
DPRINT1("Failed to read registry value, %x\n", Status);
|
||||||
RtlFreeUnicodeString(&FullLayoutPath);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memcpy(KeyboardLayoutWSTR,FullLayoutPath.Buffer, FullLayoutPath.Length);
|
|
||||||
|
DPRINT("Read registry and got %wZ\n", &LayoutFile);
|
||||||
|
|
||||||
|
Status = GetSystemDirectory(FullPathBuffer, sizeof(FullPathBuffer));
|
||||||
|
if(Status == 0 || Status > sizeof(FullPathBuffer))
|
||||||
|
{
|
||||||
|
DPRINT1("GetSystemDirectory() failed! (%d)\n", GetLastError());
|
||||||
|
RtlFreeUnicodeString(&LayoutFile);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
RtlInitUnicodeString(&FullLayoutPath, FullPathBuffer);
|
||||||
|
FullLayoutPath.MaximumLength = sizeof(FullPathBuffer);
|
||||||
|
if(FullLayoutPath.Length < FullLayoutPath.MaximumLength-1)
|
||||||
|
{
|
||||||
|
FullLayoutPath.Buffer[FullLayoutPath.Length/sizeof(WCHAR)] = '\\';
|
||||||
|
FullLayoutPath.Buffer[FullLayoutPath.Length/sizeof(WCHAR)+1] = 0;
|
||||||
|
FullLayoutPath.Length+=sizeof(WCHAR);
|
||||||
|
}
|
||||||
|
Status = RtlAppendUnicodeStringToString(&FullLayoutPath, &LayoutFile);
|
||||||
|
DPRINT("Loading Keyboard DLL %wZ\n", &FullLayoutPath);
|
||||||
|
RtlFreeUnicodeString(&LayoutFile);
|
||||||
|
|
||||||
|
if(!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT1("RtlAppendUnicodeStringToString() failed! (%x)\n", Status);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
KeyboardLayoutWSTR[FullLayoutPath.Length / sizeof(WCHAR)] = 0;
|
KBModule = LoadLibraryEx(FullPathBuffer, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
|
||||||
|
|
||||||
KBModule = LoadLibraryW(KeyboardLayoutWSTR);
|
if(!KBModule )
|
||||||
|
{
|
||||||
DPRINT( "Load Keyboard Layout: %S\n", KeyboardLayoutWSTR );
|
DPRINT1( "Failed to load %wZ, lasterror = %d\n", &FullLayoutPath, GetLastError() );
|
||||||
|
return NULL;
|
||||||
if( !KBModule )
|
}
|
||||||
DPRINT1( "Load Keyboard Layout: No %wZ\n", &FullLayoutPath );
|
|
||||||
|
|
||||||
pAddr = GetProcAddress( KBModule, (LPCSTR) 1);
|
pAddr = GetProcAddress( KBModule, (LPCSTR) 1);
|
||||||
offTable = (DWORD) pAddr - (DWORD) KBModule; // Weeks to figure this out!
|
offTable = (DWORD) pAddr - (DWORD) KBModule; // Weeks to figure this out!
|
||||||
|
@ -228,7 +237,7 @@ IntLoadKeyboardLayout( LPCWSTR pwszKLID,
|
||||||
|
|
||||||
FreeLibrary(KBModule);
|
FreeLibrary(KBModule);
|
||||||
|
|
||||||
Handle = CreateFileW( KeyboardLayoutWSTR,
|
Handle = CreateFileW( FullPathBuffer,
|
||||||
GENERIC_READ,
|
GENERIC_READ,
|
||||||
FILE_SHARE_READ,
|
FILE_SHARE_READ,
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -245,9 +254,6 @@ IntLoadKeyboardLayout( LPCWSTR pwszKLID,
|
||||||
|
|
||||||
NtClose(Handle);
|
NtClose(Handle);
|
||||||
|
|
||||||
LocalFree(KeyboardLayoutWSTR);
|
|
||||||
RtlFreeUnicodeString(&FullLayoutPath);
|
|
||||||
|
|
||||||
return hKL;
|
return hKL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue