//	Album List for Winamp
//	Copyright (C) 1999-2001 Safai Ma
//
//	This program is free software; you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation; either version 2 of the License, or
//	(at your option) any later version.
//
//	This program is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with this program; if not, write to the Free Software
//	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
/*
 * Netapi32.CPP
 *
 * Interface glue code to the Netbios
 */
#include "stdafx.h"
#include <nb30.h>

static HINSTANCE hDllNET = 0L;
static DWORD	 nRef = 0L;

static UCHAR (APIENTRY *pNetbios)(PNCB pncb)	= NULL;

void NetFree();
BOOL NetLoad()
{
	// check for multiple instances and increment reference counts.
	if (nRef != 0)
	{
		nRef++;
		return TRUE;
	}

	hDllNET = LoadLibrary("NETAPI32.DLL");
	if (!hDllNET)
	{
		NetFree();
		return FALSE;
	}

	pNetbios	= (UCHAR (APIENTRY*)(PNCB))	GetProcAddress(hDllNET, "Netbios");

	// increment reference counts
	nRef++;

	return TRUE;
}

void NetFree()
{
	// check reference count first
	if (nRef == 0) return;
	if (--nRef != 0) return;

	pNetbios	= NULL;

	FreeLibrary(hDllNET);
	hDllNET = NULL;
}

UCHAR APIENTRY Netbios(PNCB pncb)
{
	return pNetbios ? pNetbios(pncb) : NRC_SYSTEM;
}
