#include <9pm/windows.h>
#include <9pm/u.h>
#include <9pm/libc.h>


LONG APIENTRY
RegQueryValue(HKEY hKey, LPCWSTR lpSubKey, LPWSTR lpValue, PLONG lpcbValue)
{
	char *key, *value;
	long n, i, res;

	if(win_useunicode)
		return RegQueryValueW(hKey, lpSubKey, lpValue, lpcbValue);

	if(lpSubKey)
		key = win_wstr2utf(lpSubKey);
	n = *lpcbValue;	
	n >>= 1;
	value = win_malloc(n);

	value[0] = 0;
	res = RegQueryValueA(hKey, key, value, &n);
	if(res == 0) {
		for(i=0; value[i]; i++)
			lpValue[i] = value[i];
		lpValue[i] = 0;
		*lpcbValue = i*sizeof(Rune);
	}

	win_free(key);
	win_free(value);
	return res;
}
