mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-14 12:57:18 +00:00
imm32: Rewrite ImmGetIMEFileName(A|W).
This commit is contained in:
parent
8b0b53379f
commit
85489a53f5
|
@ -1802,82 +1802,49 @@ DWORD WINAPI ImmGetGuideLineW(HIMC hIMC, DWORD dwIndex, LPWSTR lpBuf, DWORD dwBu
|
|||
}
|
||||
|
||||
/***********************************************************************
|
||||
* ImmGetIMEFileNameA (IMM32.@)
|
||||
* ImmGetIMEFileNameA (IMM32.@)
|
||||
*/
|
||||
UINT WINAPI ImmGetIMEFileNameA( HKL hKL, LPSTR lpszFileName, UINT uBufLen)
|
||||
UINT WINAPI ImmGetIMEFileNameA( HKL hkl, char *bufferA, UINT lengthA )
|
||||
{
|
||||
LPWSTR bufW = NULL;
|
||||
UINT wBufLen = uBufLen;
|
||||
UINT rc;
|
||||
WCHAR *bufferW;
|
||||
DWORD lengthW;
|
||||
|
||||
if (uBufLen && lpszFileName)
|
||||
bufW = HeapAlloc(GetProcessHeap(),0,uBufLen * sizeof(WCHAR));
|
||||
else /* We need this to get the number of byte required */
|
||||
{
|
||||
bufW = HeapAlloc(GetProcessHeap(),0,MAX_PATH * sizeof(WCHAR));
|
||||
wBufLen = MAX_PATH;
|
||||
}
|
||||
TRACE( "hkl %p, bufferA %p, lengthA %d\n", hkl, bufferA, lengthA );
|
||||
|
||||
rc = ImmGetIMEFileNameW(hKL,bufW,wBufLen);
|
||||
if (!(lengthW = ImmGetIMEFileNameW( hkl, NULL, 0 ))) return 0;
|
||||
if (!(bufferW = malloc( (lengthW + 1) * sizeof(WCHAR) ))) return 0;
|
||||
lengthW = ImmGetIMEFileNameW( hkl, bufferW, lengthW + 1 );
|
||||
lengthA = WideCharToMultiByte( CP_ACP, 0, bufferW, lengthW, bufferA,
|
||||
bufferA ? lengthA : 0, NULL, NULL );
|
||||
if (bufferA) bufferA[lengthA] = 0;
|
||||
free( bufferW );
|
||||
|
||||
if (rc > 0)
|
||||
{
|
||||
if (uBufLen && lpszFileName)
|
||||
rc = WideCharToMultiByte(CP_ACP, 0, bufW, -1, lpszFileName,
|
||||
uBufLen, NULL, NULL);
|
||||
else /* get the length */
|
||||
rc = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(),0,bufW);
|
||||
return rc;
|
||||
return lengthA;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* ImmGetIMEFileNameW (IMM32.@)
|
||||
*/
|
||||
UINT WINAPI ImmGetIMEFileNameW(HKL hKL, LPWSTR lpszFileName, UINT uBufLen)
|
||||
UINT WINAPI ImmGetIMEFileNameW( HKL hkl, WCHAR *buffer, UINT length )
|
||||
{
|
||||
HKEY hkey;
|
||||
DWORD length;
|
||||
DWORD rc;
|
||||
WCHAR regKey[ARRAY_SIZE(layouts_formatW)+8];
|
||||
WCHAR path[MAX_PATH];
|
||||
HKEY hkey = 0;
|
||||
DWORD size;
|
||||
|
||||
wsprintfW( regKey, layouts_formatW, (ULONG_PTR)hKL );
|
||||
rc = RegOpenKeyW( HKEY_LOCAL_MACHINE, regKey, &hkey);
|
||||
if (rc != ERROR_SUCCESS)
|
||||
{
|
||||
SetLastError(rc);
|
||||
return 0;
|
||||
}
|
||||
TRACE( "hkl %p, buffer %p, length %u\n", hkl, buffer, length );
|
||||
|
||||
length = 0;
|
||||
rc = RegGetValueW(hkey, NULL, L"Ime File", RRF_RT_REG_SZ, NULL, NULL, &length);
|
||||
swprintf( path, ARRAY_SIZE(path), layouts_formatW, (ULONG)(ULONG_PTR)hkl );
|
||||
if (RegOpenKeyW( HKEY_LOCAL_MACHINE, path, &hkey )) return 0;
|
||||
|
||||
if (rc != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(hkey);
|
||||
SetLastError(rc);
|
||||
return 0;
|
||||
}
|
||||
if (length > uBufLen * sizeof(WCHAR) || !lpszFileName)
|
||||
{
|
||||
RegCloseKey(hkey);
|
||||
if (lpszFileName)
|
||||
{
|
||||
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return length / sizeof(WCHAR);
|
||||
}
|
||||
size = ARRAY_SIZE(path) * sizeof(WCHAR);
|
||||
if (RegGetValueW( hkey, NULL, L"Ime File", RRF_RT_REG_SZ, NULL, path, &size )) *path = 0;
|
||||
RegCloseKey( hkey );
|
||||
|
||||
RegGetValueW(hkey, NULL, L"Ime File", RRF_RT_REG_SZ, NULL, lpszFileName, &length);
|
||||
size = wcslen( path );
|
||||
if (!buffer) return size;
|
||||
|
||||
RegCloseKey(hkey);
|
||||
|
||||
return length / sizeof(WCHAR);
|
||||
lstrcpynW( buffer, path, length );
|
||||
return wcslen( buffer );
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
|
|
|
@ -2945,60 +2945,47 @@ static void test_ImmGetIMEFileName(void)
|
|||
ret = ImmGetIMEFileNameA( hkl, bufferA, 100 );
|
||||
ok( !ret, "ImmGetIMEFileNameA returned %lu\n", ret );
|
||||
ret = GetLastError();
|
||||
todo_wine
|
||||
ok( ret == 0xdeadbeef, "got error %lu\n", ret );
|
||||
|
||||
if (!(hkl = ime_install())) goto cleanup;
|
||||
|
||||
memset( bufferW, 0xcd, sizeof(bufferW) );
|
||||
ret = ImmGetIMEFileNameW( hkl, bufferW, 2 );
|
||||
todo_wine
|
||||
ok( ret == 1, "ImmGetIMEFileNameW returned %lu\n", ret );
|
||||
todo_wine
|
||||
ok( !wcscmp( bufferW, L"W" ), "got bufferW %s\n", debugstr_w(bufferW) );
|
||||
memset( bufferA, 0xcd, sizeof(bufferA) );
|
||||
ret = ImmGetIMEFileNameA( hkl, bufferA, 2 );
|
||||
ok( ret == 0, "ImmGetIMEFileNameA returned %lu\n", ret );
|
||||
todo_wine
|
||||
ok( !strcmp( bufferA, "" ), "got bufferA %s\n", debugstr_a(bufferA) );
|
||||
|
||||
swprintf( expectW, ARRAY_SIZE(expectW), L"WINE%04X.I", ime_count - 1 );
|
||||
memset( bufferW, 0xcd, sizeof(bufferW) );
|
||||
ret = ImmGetIMEFileNameW( hkl, bufferW, 11 );
|
||||
todo_wine
|
||||
ok( ret == 10, "ImmGetIMEFileNameW returned %lu\n", ret );
|
||||
todo_wine
|
||||
ok( !wcscmp( bufferW, expectW ), "got bufferW %s\n", debugstr_w(bufferW) );
|
||||
memset( bufferA, 0xcd, sizeof(bufferA) );
|
||||
ret = ImmGetIMEFileNameA( hkl, bufferA, 11 );
|
||||
ok( ret == 0, "ImmGetIMEFileNameA returned %lu\n", ret );
|
||||
todo_wine
|
||||
ok( !strcmp( bufferA, "" ), "got bufferA %s\n", debugstr_a(bufferA) );
|
||||
|
||||
swprintf( expectW, ARRAY_SIZE(expectW), L"WINE%04X.IM", ime_count - 1 );
|
||||
memset( bufferW, 0xcd, sizeof(bufferW) );
|
||||
ret = ImmGetIMEFileNameW( hkl, bufferW, 12 );
|
||||
todo_wine
|
||||
ok( ret == 11, "ImmGetIMEFileNameW returned %lu\n", ret );
|
||||
todo_wine
|
||||
ok( !wcscmp( bufferW, expectW ), "got bufferW %s\n", debugstr_w(bufferW) );
|
||||
snprintf( expectA, ARRAY_SIZE(expectA), "WINE%04X.IME", ime_count - 1 );
|
||||
memset( bufferA, 0xcd, sizeof(bufferA) );
|
||||
ret = ImmGetIMEFileNameA( hkl, bufferA, 12 );
|
||||
todo_wine
|
||||
ok( ret == 12, "ImmGetIMEFileNameA returned %lu\n", ret );
|
||||
todo_wine
|
||||
ok( !strcmp( bufferA, expectA ), "got bufferA %s\n", debugstr_a(bufferA) );
|
||||
|
||||
swprintf( expectW, ARRAY_SIZE(expectW), L"WINE%04X.IME", ime_count - 1 );
|
||||
memset( bufferW, 0xcd, sizeof(bufferW) );
|
||||
ret = ImmGetIMEFileNameW( hkl, bufferW, 13 );
|
||||
todo_wine
|
||||
ok( ret == 12, "ImmGetIMEFileNameW returned %lu\n", ret );
|
||||
ok( !wcscmp( bufferW, expectW ), "got bufferW %s\n", debugstr_w(bufferW) );
|
||||
memset( bufferA, 0xcd, sizeof(bufferA) );
|
||||
ret = ImmGetIMEFileNameA( hkl, bufferA, 13 );
|
||||
todo_wine
|
||||
ok( ret == 12, "ImmGetIMEFileNameA returned %lu\n", ret );
|
||||
ok( !strcmp( bufferA, expectA ), "got bufferA %s\n", debugstr_a(bufferA) );
|
||||
|
||||
|
|
Loading…
Reference in a new issue