#include "CWrapper.h"


extern "C"
{
	
	VIHANDLE __cdecl VICreate()
	{
		return (VIHANDLE)new videoInput();
	}

	INT __cdecl VIListDevices(VIHANDLE lpVi)
	{		
		return (static_cast<videoInput*>(lpVi))->listDevices(true);
	}

	VOID __cdecl VIGetDeviceName(INT iDeviceID, LPWSTR lpszBuffer, INT cBufferSize, VIHANDLE lpVi)
	{
		MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
			(static_cast<videoInput*>(lpVi))->getDeviceName(iDeviceID), -1,
			lpszBuffer, cBufferSize);
	}

	BOOL __cdecl VISetupDevice(INT iDeviceID, INT iWidth, INT iHeight, VIHANDLE lpVi)
	{
		(static_cast<videoInput*>(lpVi))->setUseCallback(false);
		return (static_cast<videoInput*>(lpVi))->setupDevice(iDeviceID, iWidth, iHeight);
	}

	BOOL __cdecl VIDefSetupDevice(INT iDeviceID, VIHANDLE lpVi)
	{
		return (static_cast<videoInput*>(lpVi))->setupDevice(iDeviceID);
	}

	VOID __cdecl VIStopDevice(INT iDeviceID, VIHANDLE lpVi)
	{
		(static_cast<videoInput*>(lpVi))->stopDevice(iDeviceID);
	}

	BOOL __cdecl VIIsFrameNew(INT iDeviceID, VIHANDLE lpVi)
	{
		return (static_cast<videoInput*>(lpVi))->isFrameNew(iDeviceID);
	}

	INT __cdecl VIGetSize(INT iDeviceID, VIHANDLE lpVi)
	{
		return (static_cast<videoInput*>(lpVi))->getSize(iDeviceID);		
	}

	INT __cdecl VIGetWidth(INT iDeviceID, VIHANDLE lpVi)
	{
		return (static_cast<videoInput*>(lpVi))->getWidth(iDeviceID);
	}

	INT __cdecl VIGetHeight(INT iDeviceID, VIHANDLE lpVi)
	{
		return (static_cast<videoInput*>(lpVi))->getHeight(iDeviceID);
	}

	BOOL __cdecl VIGrabFrame(INT iDeviceID, LPBYTE lpBuffer, VIHANDLE lpVi)
	{		
		return (static_cast<videoInput*>(lpVi))->getPixels(iDeviceID, lpBuffer, true, true);
	}

	VOID __cdecl VIShowSettings(INT iDeviceID, VIHANDLE lpVi)
	{
		(static_cast<videoInput*>(lpVi))->showSettingsWindow(iDeviceID);
	}

	BOOL __cdecl VIIsSetUp(INT iDeviceID, VIHANDLE lpVi)
	{
		return (BOOL)((static_cast<videoInput*>(lpVi))->isDeviceSetup(iDeviceID));
	}
	
	VOID __cdecl VIClose(VIHANDLE lpVi)
	{		
		delete (static_cast<videoInput*>(lpVi));
	}
}