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

HINSTANCE APIENTRY
FindExecutable(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
{
	char *file, *dir, *exec;
	HINSTANCE res;
	int i;

	if(win_useunicode)
		return FindExecutableW(lpFile, lpDirectory, lpResult);

	file = win_wstr2utf(lpFile);
	dir = win_wstr2utf(lpDirectory);

	exec = win_malloc(MAX_PATH);
	exec[0] = 0;
	res = FindExecutableA(file, dir, exec);
	
	for(i=0; exec[i]; i++)
		lpResult[i] = exec[i];
	lpResult[i] = 0;
	win_free(exec);

	return res;	
}
