Commit 85489a53 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

imm32: Rewrite ImmGetIMEFileName(A|W).

parent 8b0b5337
...@@ -1802,82 +1802,49 @@ DWORD WINAPI ImmGetGuideLineW(HIMC hIMC, DWORD dwIndex, LPWSTR lpBuf, DWORD dwBu ...@@ -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; WCHAR *bufferW;
UINT wBufLen = uBufLen; DWORD lengthW;
UINT rc;
if (uBufLen && lpszFileName) TRACE( "hkl %p, bufferA %p, lengthA %d\n", hkl, bufferA, lengthA );
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;
}
rc = ImmGetIMEFileNameW(hKL,bufW,wBufLen);
if (rc > 0) if (!(lengthW = ImmGetIMEFileNameW( hkl, NULL, 0 ))) return 0;
{ if (!(bufferW = malloc( (lengthW + 1) * sizeof(WCHAR) ))) return 0;
if (uBufLen && lpszFileName) lengthW = ImmGetIMEFileNameW( hkl, bufferW, lengthW + 1 );
rc = WideCharToMultiByte(CP_ACP, 0, bufW, -1, lpszFileName, lengthA = WideCharToMultiByte( CP_ACP, 0, bufferW, lengthW, bufferA,
uBufLen, NULL, NULL); bufferA ? lengthA : 0, NULL, NULL );
else /* get the length */ if (bufferA) bufferA[lengthA] = 0;
rc = WideCharToMultiByte(CP_ACP, 0, bufW, -1, NULL, 0, NULL, free( bufferW );
NULL);
}
HeapFree(GetProcessHeap(),0,bufW); return lengthA;
return rc;
} }
/*********************************************************************** /***********************************************************************
* ImmGetIMEFileNameW (IMM32.@) * ImmGetIMEFileNameW (IMM32.@)
*/ */
UINT WINAPI ImmGetIMEFileNameW(HKL hKL, LPWSTR lpszFileName, UINT uBufLen) UINT WINAPI ImmGetIMEFileNameW( HKL hkl, WCHAR *buffer, UINT length )
{ {
HKEY hkey; WCHAR path[MAX_PATH];
DWORD length; HKEY hkey = 0;
DWORD rc; DWORD size;
WCHAR regKey[ARRAY_SIZE(layouts_formatW)+8];
wsprintfW( regKey, layouts_formatW, (ULONG_PTR)hKL );
rc = RegOpenKeyW( HKEY_LOCAL_MACHINE, regKey, &hkey);
if (rc != ERROR_SUCCESS)
{
SetLastError(rc);
return 0;
}
length = 0; TRACE( "hkl %p, buffer %p, length %u\n", hkl, buffer, length );
rc = RegGetValueW(hkey, NULL, L"Ime File", RRF_RT_REG_SZ, NULL, NULL, &length);
if (rc != ERROR_SUCCESS) swprintf( path, ARRAY_SIZE(path), layouts_formatW, (ULONG)(ULONG_PTR)hkl );
{ if (RegOpenKeyW( HKEY_LOCAL_MACHINE, path, &hkey )) return 0;
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);
}
RegGetValueW(hkey, NULL, L"Ime File", RRF_RT_REG_SZ, NULL, lpszFileName, &length); size = ARRAY_SIZE(path) * sizeof(WCHAR);
if (RegGetValueW( hkey, NULL, L"Ime File", RRF_RT_REG_SZ, NULL, path, &size )) *path = 0;
RegCloseKey( hkey );
RegCloseKey(hkey); size = wcslen( path );
if (!buffer) return size;
return length / sizeof(WCHAR); lstrcpynW( buffer, path, length );
return wcslen( buffer );
} }
/*********************************************************************** /***********************************************************************
......
...@@ -2945,60 +2945,47 @@ static void test_ImmGetIMEFileName(void) ...@@ -2945,60 +2945,47 @@ static void test_ImmGetIMEFileName(void)
ret = ImmGetIMEFileNameA( hkl, bufferA, 100 ); ret = ImmGetIMEFileNameA( hkl, bufferA, 100 );
ok( !ret, "ImmGetIMEFileNameA returned %lu\n", ret ); ok( !ret, "ImmGetIMEFileNameA returned %lu\n", ret );
ret = GetLastError(); ret = GetLastError();
todo_wine
ok( ret == 0xdeadbeef, "got error %lu\n", ret ); ok( ret == 0xdeadbeef, "got error %lu\n", ret );
if (!(hkl = ime_install())) goto cleanup; if (!(hkl = ime_install())) goto cleanup;
memset( bufferW, 0xcd, sizeof(bufferW) ); memset( bufferW, 0xcd, sizeof(bufferW) );
ret = ImmGetIMEFileNameW( hkl, bufferW, 2 ); ret = ImmGetIMEFileNameW( hkl, bufferW, 2 );
todo_wine
ok( ret == 1, "ImmGetIMEFileNameW returned %lu\n", ret ); ok( ret == 1, "ImmGetIMEFileNameW returned %lu\n", ret );
todo_wine
ok( !wcscmp( bufferW, L"W" ), "got bufferW %s\n", debugstr_w(bufferW) ); ok( !wcscmp( bufferW, L"W" ), "got bufferW %s\n", debugstr_w(bufferW) );
memset( bufferA, 0xcd, sizeof(bufferA) ); memset( bufferA, 0xcd, sizeof(bufferA) );
ret = ImmGetIMEFileNameA( hkl, bufferA, 2 ); ret = ImmGetIMEFileNameA( hkl, bufferA, 2 );
ok( ret == 0, "ImmGetIMEFileNameA returned %lu\n", ret ); ok( ret == 0, "ImmGetIMEFileNameA returned %lu\n", ret );
todo_wine
ok( !strcmp( bufferA, "" ), "got bufferA %s\n", debugstr_a(bufferA) ); ok( !strcmp( bufferA, "" ), "got bufferA %s\n", debugstr_a(bufferA) );
swprintf( expectW, ARRAY_SIZE(expectW), L"WINE%04X.I", ime_count - 1 ); swprintf( expectW, ARRAY_SIZE(expectW), L"WINE%04X.I", ime_count - 1 );
memset( bufferW, 0xcd, sizeof(bufferW) ); memset( bufferW, 0xcd, sizeof(bufferW) );
ret = ImmGetIMEFileNameW( hkl, bufferW, 11 ); ret = ImmGetIMEFileNameW( hkl, bufferW, 11 );
todo_wine
ok( ret == 10, "ImmGetIMEFileNameW returned %lu\n", ret ); ok( ret == 10, "ImmGetIMEFileNameW returned %lu\n", ret );
todo_wine
ok( !wcscmp( bufferW, expectW ), "got bufferW %s\n", debugstr_w(bufferW) ); ok( !wcscmp( bufferW, expectW ), "got bufferW %s\n", debugstr_w(bufferW) );
memset( bufferA, 0xcd, sizeof(bufferA) ); memset( bufferA, 0xcd, sizeof(bufferA) );
ret = ImmGetIMEFileNameA( hkl, bufferA, 11 ); ret = ImmGetIMEFileNameA( hkl, bufferA, 11 );
ok( ret == 0, "ImmGetIMEFileNameA returned %lu\n", ret ); ok( ret == 0, "ImmGetIMEFileNameA returned %lu\n", ret );
todo_wine
ok( !strcmp( bufferA, "" ), "got bufferA %s\n", debugstr_a(bufferA) ); ok( !strcmp( bufferA, "" ), "got bufferA %s\n", debugstr_a(bufferA) );
swprintf( expectW, ARRAY_SIZE(expectW), L"WINE%04X.IM", ime_count - 1 ); swprintf( expectW, ARRAY_SIZE(expectW), L"WINE%04X.IM", ime_count - 1 );
memset( bufferW, 0xcd, sizeof(bufferW) ); memset( bufferW, 0xcd, sizeof(bufferW) );
ret = ImmGetIMEFileNameW( hkl, bufferW, 12 ); ret = ImmGetIMEFileNameW( hkl, bufferW, 12 );
todo_wine
ok( ret == 11, "ImmGetIMEFileNameW returned %lu\n", ret ); ok( ret == 11, "ImmGetIMEFileNameW returned %lu\n", ret );
todo_wine
ok( !wcscmp( bufferW, expectW ), "got bufferW %s\n", debugstr_w(bufferW) ); ok( !wcscmp( bufferW, expectW ), "got bufferW %s\n", debugstr_w(bufferW) );
snprintf( expectA, ARRAY_SIZE(expectA), "WINE%04X.IME", ime_count - 1 ); snprintf( expectA, ARRAY_SIZE(expectA), "WINE%04X.IME", ime_count - 1 );
memset( bufferA, 0xcd, sizeof(bufferA) ); memset( bufferA, 0xcd, sizeof(bufferA) );
ret = ImmGetIMEFileNameA( hkl, bufferA, 12 ); ret = ImmGetIMEFileNameA( hkl, bufferA, 12 );
todo_wine
ok( ret == 12, "ImmGetIMEFileNameA returned %lu\n", ret ); ok( ret == 12, "ImmGetIMEFileNameA returned %lu\n", ret );
todo_wine
ok( !strcmp( bufferA, expectA ), "got bufferA %s\n", debugstr_a(bufferA) ); ok( !strcmp( bufferA, expectA ), "got bufferA %s\n", debugstr_a(bufferA) );
swprintf( expectW, ARRAY_SIZE(expectW), L"WINE%04X.IME", ime_count - 1 ); swprintf( expectW, ARRAY_SIZE(expectW), L"WINE%04X.IME", ime_count - 1 );
memset( bufferW, 0xcd, sizeof(bufferW) ); memset( bufferW, 0xcd, sizeof(bufferW) );
ret = ImmGetIMEFileNameW( hkl, bufferW, 13 ); ret = ImmGetIMEFileNameW( hkl, bufferW, 13 );
todo_wine
ok( ret == 12, "ImmGetIMEFileNameW returned %lu\n", ret ); ok( ret == 12, "ImmGetIMEFileNameW returned %lu\n", ret );
ok( !wcscmp( bufferW, expectW ), "got bufferW %s\n", debugstr_w(bufferW) ); ok( !wcscmp( bufferW, expectW ), "got bufferW %s\n", debugstr_w(bufferW) );
memset( bufferA, 0xcd, sizeof(bufferA) ); memset( bufferA, 0xcd, sizeof(bufferA) );
ret = ImmGetIMEFileNameA( hkl, bufferA, 13 ); ret = ImmGetIMEFileNameA( hkl, bufferA, 13 );
todo_wine
ok( ret == 12, "ImmGetIMEFileNameA returned %lu\n", ret ); ok( ret == 12, "ImmGetIMEFileNameA returned %lu\n", ret );
ok( !strcmp( bufferA, expectA ), "got bufferA %s\n", debugstr_a(bufferA) ); ok( !strcmp( bufferA, expectA ), "got bufferA %s\n", debugstr_a(bufferA) );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment