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

DWORD WINAPI
WNetOpenEnum(DWORD dwScope, DWORD dwType, DWORD dwUsage,
	LPNETRESOURCEW lpNetResource, LPHANDLE lphEnum)
{
	DWORD d;
	NETRESOURCEA res, *p;

	if(win_useunicode)
		return WNetOpenEnumW(dwScope, dwType, dwUsage,
			lpNetResource, lphEnum);

	if(lpNetResource != 0) {
		p = &res;
		memset(&res, 0, sizeof(res));
		res.dwScope = lpNetResource->dwScope;
		res.dwType = lpNetResource->dwType;
		res.dwDisplayType = lpNetResource->dwDisplayType;
		res.dwUsage = lpNetResource->dwUsage;
		res.lpLocalName = win_wstr2utf(lpNetResource->lpLocalName);
		res.lpRemoteName = win_wstr2utf(lpNetResource->lpRemoteName);
		res.lpComment = win_wstr2utf(lpNetResource->lpComment);
		res.lpProvider = win_wstr2utf(lpNetResource->lpProvider);
	} else
		p = 0;

	d = WNetOpenEnumA(dwScope, dwType, dwUsage, p, lphEnum);
	win_free(lpNetResource->lpLocalName);
	win_free(lpNetResource->lpRemoteName);
	win_free(lpNetResource->lpComment);
	win_free(lpNetResource->lpProvider);
	return d;
}
