/*
 * Copyright (C) 2005 Damjan Jovanovic
 * Based on:
 *   - Sti.h from Visual Studio .NET 2003 (find it on www.icarusindie.com :-)
 *   - STI documentation from the MSDN library docs
 *   - the work of:
 * Copyright (C) 2004 Mike McCormack
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import "wtypes.idl";
import "oaidl.idl";
cpp_quote("#include \"pshpack8.h\"")
cpp_quote("#include \"stireg.h\"")
cpp_quote("#include \"stierr.h\"")

cpp_quote("#define __OVERLAPPED_FWD_DEFINED__")
interface OVERLAPPED;
interface HINSTANCE;
//typedef [transmit_as(unsigned long)] void *HINSTANCE;

/* encoding neutral interfaces */
/*struct STIDEVICE;
typedef struct STIDEVICE* PSTIDEVICE ;
struct IStillImage;
struct STI;
typedef struct STI *PSTI;

struct STIDEVICEW;

typedef struct IStillImageW IStillImageW,*PSTIW;
typedef struct STIDEVICEW* PSTIDEVICEW;

struct STIDEVICEA;

typedef struct IStillImageA IStillImageA,*PSTIA;
typedef struct STIDEVICEA* PSTIDEVICEA;

HRESULT WINAPI StiCreateInstanceA(HINSTANCE hinst, DWORD ver, PSTIA *ppSti, void **punk);
HRESULT WINAPI StiCreateInstanceW(HINSTANCE hinst, DWORD ver, PSTIW *ppSti, void **punk);
*/


















cpp_quote("#define STI_UNICODE	1")

/* STI version */
cpp_quote("#define STI_VERSION_FLAG_MASK		0xFF000000")
cpp_quote("#define STI_VERSION_FLAG_UNICODE	0x01000000")
cpp_quote("#define STI_VERSION_MIN_ALLOWED		0x00000002")
cpp_quote("#define STI_VERSION_REAL			0x00000002")
cpp_quote("#define GET_STIVER_MAJOR(dwVersion)	(HIWORD(dwVersion) & ~STI_VERSION_FLAG_MASK)")
cpp_quote("#define GET_STIVER_MINOR(dwVersion)	LOWORD(dwVersion)")

cpp_quote("#if defined(UNICODE) || defined(STI_UNICODE)")
cpp_quote("#define STI_VERSION					(STI_VERSION_REAL | STI_VERSION_FLAG_UNICODE)")
cpp_quote("#else")
cpp_quote("#define STI_VERSION					(STI_VERSION_REAL)")
cpp_quote("#endif")



/* Array sizes */
cpp_quote("#define STI_MAX_INTERNAL_NAME_LENGTH	128")
cpp_quote("#define MAX_NOTIFICATION_DATA	64")
#define STI_MAX_INTERNAL_NAME_LENGTH	128
#define MAX_NOTIFICATION_DATA	64



/* Types */
typedef DWORD STI_DEVICE_TYPE;
typedef DWORD STI_RAW_CONTROL_CODE;
typedef struct IStiDevice STIDEVICE, *PSTIDEVICE;
typedef struct IStillImageA STIIMAGEA, *PSTIIMAGEA, STIA, *PSTIA;
typedef struct IStillImageW STIIMAGEW, *PSTIIMAGEW, STIW, *PSTIW;
cpp_quote("#if defined(UNICODE) || defined(STI_UNICODE)")
cpp_quote("typedef STIIMAGEW IStillImage, STI, *PSTI;")
cpp_quote("#else")
cpp_quote("typedef STIIMAGEA IStillImage, STI, *PSTI;")
cpp_quote("#endif")



typedef enum _STI_DEVICE_MJ_TYPE
{
	StiDeviceTypeDefault = 0,
	StiDeviceTypeScanner = 1,
	StiDeviceTypeDigitalCamera = 2,
	StiDeviceTypeStreamingVideo = 3
} STI_DEVICE_MJ_TYPE;

cpp_quote("#define GET_STIDEVICE_TYPE(dwDevType) HIWORD(dwDevType)")
cpp_quote("#define GET_STIDEVICE_SUBTYPE(dwDevType) LOWORD(dwDevType)")



typedef struct _STI_DEV_CAPS {
	DWORD dwGeneric;
} STI_DEV_CAPS, *PSTI_DEV_CAPS;

/* Possible values for dwGeneric: */
cpp_quote("#define STI_GENCAP_AUTO_PORTSELECT	0x00000008")
cpp_quote("#define STI_GENCAP_GENERATE_ARRIVALEVENT	0x00000004")
cpp_quote("#define STI_GENCAP_NOTIFICATIONS	0x00000001")
cpp_quote("#define STI_GENCAP_POLLING_NEEDED	0x00000002")
cpp_quote("#define STI_GENCAP_SUBSET	0x00000020")
cpp_quote("#define STI_GENCAP_WIA	0x00000010")



typedef struct _STI_DEVICE_INFORMATIONA {
	DWORD dwSize;
	STI_DEVICE_TYPE DeviceType;
	CHAR szDeviceInternalName[STI_MAX_INTERNAL_NAME_LENGTH];
	STI_DEV_CAPS DeviceCapabilities;
	DWORD dwHardwareConfiguration;
	LPSTR pszVendorDescription;
	LPSTR pszDeviceDescription;
	LPSTR pszPortName;
	LPSTR pszPropProvider;
	LPSTR pszLocalName;
} STI_DEVICE_INFORMATIONA, *PSTI_DEVICE_INFORMATIONA;

typedef struct _STI_DEVICE_INFORMATIONW {
	DWORD dwSize;
	STI_DEVICE_TYPE DeviceType;
	WCHAR szDeviceInternalName[STI_MAX_INTERNAL_NAME_LENGTH];
	STI_DEV_CAPS DeviceCapabilities;
	DWORD dwHardwareConfiguration;
	LPWSTR pszVendorDescription;
	LPWSTR pszDeviceDescription;
	LPWSTR pszPortName;
	LPWSTR pszPropProvider;
	LPWSTR pszLocalName;
} STI_DEVICE_INFORMATIONW, *PSTI_DEVICE_INFORMATIONW;

cpp_quote("#if defined(UNICODE) || defined(STI_UNICODE)")
cpp_quote("typedef STI_DEVICE_INFORMATIONW STI_DEVICE_INFORMATION;")
cpp_quote("typedef PSTI_DEVICE_INFORMATIONW PSTI_DEVICE_INFORMATION;")
cpp_quote("#else")
cpp_quote("typedef STI_DEVICE_INFORMATIONA STI_DEVICE_INFORMATION;")
cpp_quote("typedef PSTI_DEVICE_INFORMATIONA PSTI_DEVICE_INFORMATION;")
cpp_quote("#endif")

/* Possible values for dwHardwareConfiguration: */
cpp_quote("#define STI_HW_CONFIG_UNKNOWN	0x0001")
cpp_quote("#define STI_HW_CONFIG_SCSI		0x0002")
cpp_quote("#define STI_HW_CONFIG_USB		0x0004")
cpp_quote("#define STI_HW_CONFIG_SERIAL	0x0008")
cpp_quote("#define STI_HW_CONFIG_PARALLEL	0x0010")



typedef struct _STI_DEVICE_STATUS {
	DWORD dwSize;
	DWORD StatusMask;
	DWORD dwOnlineState;
	DWORD dwHardwareStatusCode;
	DWORD dwEventHandlingState;
	DWORD dwPollingInterval;
} STI_DEVICE_STATUS, *PSTI_DEVICE_STATUS;

/* Possible values for StatusMask: */
cpp_quote("#define STI_DEVSTATUS_ONLINE_STATE	0x0001")
cpp_quote("#define STI_DEVSTATUS_EVENTS_STATE	0x0002")

/* Possible values for dwOnlineState: */
cpp_quote("#define STI_ONLINESTATE_OPERATIONAL			0x00000001")
cpp_quote("#define STI_ONLINESTATE_PENDING				0x00000002")
cpp_quote("#define STI_ONLINESTATE_ERROR				0x00000004")
cpp_quote("#define STI_ONLINESTATE_PAUSED				0x00000008")
cpp_quote("#define STI_ONLINESTATE_PAPER_JAM			0x00000010")
cpp_quote("#define STI_ONLINESTATE_PAPER_PROBLEM		0x00000020")
cpp_quote("#define STI_ONLINESTATE_OFFLINE				0x00000040")
cpp_quote("#define STI_ONLINESTATE_IO_ACTIVE			0x00000080")
cpp_quote("#define STI_ONLINESTATE_BUSY				0x00000100")
cpp_quote("#define STI_ONLINESTATE_TRANSFERRING		0x00000200")
cpp_quote("#define STI_ONLINESTATE_INITIALIZING		0x00000400")
cpp_quote("#define STI_ONLINESTATE_WARMING_UP			0x00000800")
cpp_quote("#define STI_ONLINESTATE_USER_INTERVENTION	0x00001000")
cpp_quote("#define STI_ONLINESTATE_POWER_SAVE			0x00002000")

/* Possible values for dwEventHandlingState: */
cpp_quote("#define STI_EVENTHANDLING_ENABLED			0x00000001")
cpp_quote("#define STI_EVENTHANDLING_POLLING			0x00000002")
cpp_quote("#define STI_EVENTHANDLING_PENDING			0x00000004")



typedef struct _ERROR_INFOA {
    DWORD dwSize;
    DWORD dwGenericError;
    DWORD dwVendorError;
    CHAR szExtendedErrorText[255];
} STI_ERROR_INFOA, *PSTI_ERROR_INFOA;

typedef struct _ERROR_INFOW {
    DWORD dwSize;
    DWORD dwGenericError;
    DWORD dwVendorError;
    WCHAR szExtendedErrorText[255];
} STI_ERROR_INFOW, *PSTI_ERROR_INFOW;

cpp_quote("#if defined(UNICODE) || defined(STI_UNICODE)")
cpp_quote("typedef STI_ERROR_INFOW STI_ERROR_INFO;")
cpp_quote("typedef PSTI_ERROR_INFOW PSTI_ERROR_INFO;")
cpp_quote("#else")
cpp_quote("typedef STI_ERROR_INFOA STI_ERROR_INFO;")
cpp_quote("typedef PSTI_ERROR_INFOA PSTI_ERROR_INFO;")
cpp_quote("#endif")

typedef struct _STI_DIAG {
	DWORD dwSize;
	DWORD dwBasicDiagCode;
	DWORD dwVendorDiagCode;
	DWORD dwStatusMask;
	STI_ERROR_INFOW sErrorInfo;
} STI_DIAG, *LPSTI_DIAG;



typedef struct _STI_WIA_DEVICE_INFORMATIONA {
	DWORD dwSize;
	STI_DEVICE_TYPE DeviceType;
	CHAR szDeviceInternalName[STI_MAX_INTERNAL_NAME_LENGTH];
	STI_DEV_CAPS DeviceCapabilities;
	DWORD dwHardwareConfiguration;
	LPSTR pszVendorDescription;
	LPSTR pszDeviceDescription;
	LPSTR pszPortName;
	LPSTR pszPropProvider;
	LPSTR pszLocalName;
	LPSTR pszUiDll;
	LPSTR pszServer;
} STI_WIA_DEVICE_INFORMATIONA, *PSTI_WIA_DEVICE_INFORMATIONA;

typedef struct _STI_WIA_DEVICE_INFORMATIONW {
	DWORD dwSize;
	STI_DEVICE_TYPE DeviceType;
	WCHAR szDeviceInternalName[STI_MAX_INTERNAL_NAME_LENGTH];
	STI_DEV_CAPS DeviceCapabilities;
	DWORD dwHardwareConfiguration;
	LPWSTR pszVendorDescription;
	LPWSTR pszDeviceDescription;
	LPWSTR pszPortName;
	LPWSTR pszPropProvider;
	LPWSTR pszLocalName;
	LPWSTR pszUiDll;
	LPWSTR pszServer;
} STI_WIA_DEVICE_INFORMATIONW, *PSTI_WIA_DEVICE_INFORMATIONW;

cpp_quote("#if defined(UNICODE) || defined(STI_UNICODE)")
cpp_quote("typedef STI_WIA_DEVICE_INFORMATIONW STI_WIA_DEVICE_INFORMATION;")
cpp_quote("typedef PSTI_WIA_DEVICE_INFORMATIONW PSTI_WIA_DEVICE_INFORMATION;")
cpp_quote("#else")
cpp_quote("typedef STI_WIA_DEVICE_INFORMATIONA STI_WIA_DEVICE_INFORMATION;")
cpp_quote("typedef PSTI_WIA_DEVICE_INFORMATIONA PSTI_WIA_DEVICE_INFORMATION;")
cpp_quote("#endif")



typedef struct _STINOTIFY {
	DWORD dwSize;
	GUID guidNotificationCode;
	BYTE abNotificationData[MAX_NOTIFICATION_DATA];
} STINOTIFY, *LPSTINOTIFY;



typedef struct _STISUBSCRIBE {
	DWORD dwSize;
	DWORD dwFlags;
	DWORD dwFilter;
	HWND hWndNotify;
	HANDLE hEvent;
	UINT uiNotificationMessage;
} STISUBSCRIBE, *LPSTISUBSCRIBE;

/* Possible values for dwFlags: */
cpp_quote("#define STI_SUBSCRIBE_FLAG_WINDOW	0x0001")
cpp_quote("#define STI_SUBSCRIBE_FLAG_EVENT	0x0002")




cpp_quote("#define STI_TRACE_INFORMATION	0x00000001")
cpp_quote("#define STI_TRACE_WARNING		0x00000002")
cpp_quote("#define STI_TRACE_ERROR			0x00000004")






















/*****************************************************************************
 * IStiDevice
 */
[
  object,
  uuid(6CFA5A80-2DC8-11D0-90EA-00AA0060F86C),
  pointer_default(unique),
  implicit_handle(handle_t bindingHandle)
]
interface IStiDevice : IUnknown
{
[local] HRESULT Initialize(HINSTANCE hinst, LPCWSTR pwszDeviceName, DWORD dwVersion, DWORD dwMode);
[local] HRESULT GetCapabilities(PSTI_DEV_CAPS pDevCaps);
[local] HRESULT GetStatus(PSTI_DEVICE_STATUS pDevStatus);
[local] HRESULT DeviceReset();
[local] HRESULT Diagnostic(LPSTI_DIAG pBuffer);
[local] HRESULT Escape(STI_RAW_CONTROL_CODE EscapeFunction, LPVOID lpInData, DWORD cbInDataSize, LPVOID pOutData, DWORD dwOutDataSize, DWORD *pdwActualData);
[local] HRESULT GetLastError(DWORD *pdwLastDeviceError);
[local] HRESULT LockDevice(DWORD dwTimeOut);
[local] HRESULT UnLockDevice();
[local] HRESULT RawReadData(LPVOID lpBuffer, DWORD *lpdwNumberOfBytes, OVERLAPPED *lpOverlapped);
[local] HRESULT RawWriteData(LPVOID lpBuffer, DWORD nNumberOfBytes, OVERLAPPED *lpOverlapped);
[local] HRESULT RawReadCommand(LPVOID lpBuffer, DWORD *lpdwNumberOfBytes, OVERLAPPED *lpOverlapped);
[local] HRESULT RawWriteCommand(LPVOID lpBuffer, DWORD nNumberOfBytes, OVERLAPPED *lpOverlapped);
        HRESULT Subscribe(LPSTISUBSCRIBE lpSubscribe);
        HRESULT GetLastNotificationData(LPSTINOTIFY lpNotify);
        HRESULT UnSubscribe();
[local] HRESULT GetLastErrorInfo(STI_ERROR_INFOA *pLastErrorInfo);
}

/*****************************************************************************
 * IStillImageW
 */
[
  object,
  uuid(641BD880-2DC8-11D0-90EA-00AA0060F86C),
  pointer_default(unique),
  implicit_handle(handle_t bindingHandle)
]
interface IStillImageW : IUnknown
{
[local] HRESULT Initialize(HINSTANCE hinst, DWORD dwVersion);
[local] HRESULT GetDeviceList(DWORD dwType, DWORD dwFlags, DWORD *pdwItemsReturned, LPVOID* ppBuffer);
[local] HRESULT GetDeviceInfo(LPWSTR pwszDeviceName, LPVOID* ppBuffer);
        HRESULT CreateDevice(LPWSTR pwszDeviceName, DWORD dwMode, IStiDevice* pDevice, LPUNKNOWN* punkOuter);
[local] HRESULT GetDeviceValue(LPWSTR pwszDeviceName, LPWSTR pValueName, DWORD *pType, BYTE *pData, DWORD *cbData);
[local] HRESULT SetDeviceValue(LPWSTR pwszDeviceName, LPWSTR pValueName, DWORD Type, BYTE *pData, DWORD cbData);
[local] HRESULT GetSTILaunchInformation(LPWSTR pwszDeviceName, DWORD *pdwEventCode, LPWSTR pwszEventName);
[local] HRESULT RegisterLaunchApplication(LPWSTR pwszAppName, LPWSTR pwszCommandLine);
[local] HRESULT UnregisterLaunchApplication(LPWSTR pwszAppName);
        HRESULT EnableHwNotifications(LPCWSTR pwszDeviceName, BOOL bNewState);
        HRESULT GetHwNotificationState(LPCWSTR pwszDeviceName, BOOL *pbCurrentState);
        HRESULT RefreshDeviceBus(LPCWSTR pwszDeviceName);
        HRESULT LaunchApplicationForDevice(LPWSTR pwszDeviceName, LPWSTR pwszAppName, LPSTINOTIFY pStiNotify);
        HRESULT SetupDeviceParameters(PSTI_DEVICE_INFORMATIONW pDevInfo);
        HRESULT WriteToErrorLog(DWORD dwMessageType, LPCWSTR pszMessage);
}


/*****************************************************************************
 * IStillImageA
 */
[
  object,
  uuid(A7B1F740-1D7F-11D1-ACA9-00A02438AD48),
  pointer_default(unique),
  implicit_handle(handle_t bindingHandle)
]
interface IStillImageA : IUnknown
{
[local] HRESULT Initialize(HINSTANCE hinst, DWORD dwVersion);
[local] HRESULT GetDeviceList(DWORD dwType, DWORD dwFlags, DWORD *pdwItemsReturned, LPVOID* ppBuffer);
[local] HRESULT GetDeviceInfo(LPCSTR pwszDeviceName, LPVOID* ppBuffer);
        HRESULT CreateDevice(LPCSTR pwszDeviceName, DWORD dwMode, IStiDevice* pDevice, LPUNKNOWN* punkOuter);
[local] HRESULT GetDeviceValue(LPSTR pwszDeviceName, LPSTR pValueName, DWORD *pType, BYTE *pData, DWORD *cbData);
[local] HRESULT SetDeviceValue(LPSTR pwszDeviceName, LPSTR pValueName, DWORD Type, BYTE *pData, DWORD cbData);
[local] HRESULT GetSTILaunchInformation(LPSTR pwszDeviceName, DWORD *pdwEventCode, LPSTR pwszEventName);
[local] HRESULT RegisterLaunchApplication(LPSTR pwszAppName, LPSTR pwszCommandLine);
[local] HRESULT UnregisterLaunchApplication(LPSTR pwszAppName);
        HRESULT EnableHwNotifications(LPCSTR pwszDeviceName, BOOL bNewState);
        HRESULT GetHwNotificationState(LPCSTR pwszDeviceName, BOOL *pbCurrentState);     HRESULT RefreshDeviceBus(LPCSTR pwszDeviceName);
        HRESULT LaunchApplicationForDevice(LPSTR pwszDeviceName, LPSTR pwszAppName, LPSTINOTIFY pStiNotify);
        HRESULT SetupDeviceParameters(PSTI_DEVICE_INFORMATIONA pDevInfo);
        HRESULT WriteToErrorLog(DWORD dwMessageType, LPCSTR pszMessage);
}

cpp_quote("STDMETHODIMP StiCreateInstanceA(HINSTANCE, DWORD, IStillImageA **, LPUNKNOWN);")
cpp_quote("STDMETHODIMP StiCreateInstanceW(HINSTANCE, DWORD, IStillImageW **, LPUNKNOWN);")

cpp_quote("#include \"poppack.h\"")
