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


LONG APIENTRY
RegSetValueEx(HKEY hKey, LPCWSTR lpValueName, DWORD Reserved, DWORD dwType, BYTE* lpData, DWORD cbData)
{
	char *name;
	void *data;
	int n;
	LONG res;

	if(win_useunicode)
		return RegSetValueExW(hKey, lpValueName, Reserved, dwType, lpData, cbData);
	
	if(lpValueName)
		name = win_wstr2utf(lpValueName);
	else
		name = 0;

	switch(dwType) {
	default:
		win_fatal("RegSetValueEx: unknown data type");
	case REG_BINARY:
	case REG_DWORD:
//	case REG_DWORD_LITTLE_ENDIAN:
	case REG_DWORD_BIG_ENDIAN:
	case REG_LINK:
	case REG_NONE:
		data = lpData;
		n = cbData;
		break;
	case REG_EXPAND_SZ:
	case REG_SZ:
	case REG_MULTI_SZ:
	case REG_RESOURCE_LIST:
		win_fatal("RegSetValueEx: not done yet");
	}

	res = RegSetValueExA(hKey, name, Reserved, dwType, data, n);
	win_free(name);

	if(data != lpData)
		; // win_free data
	return res;
}


