////////////////////////////////////////////
//                                        // 
//  SWAPI.H - SuperWedge API definitions  //
//                                        //
////////////////////////////////////////////

#ifndef SWAPI_H_DEFINED
#define SWAPI_H_DEFINED

#include <windows.h>

//
// Windows Messages
//
#define WM_SW_API_BASE              WM_USER + 0x170

// connection APIs
#define WM_SW_REGISTERCLIENT        WM_SW_API_BASE + 0x00
#define WM_SW_DEREGISTERCLIENT      WM_SW_API_BASE + 0x01
#define WM_SW_BUFFERED_MODE         WM_SW_API_BASE + 0x02
#define WM_SW_GET_VERSION           WM_SW_API_BASE + 0x03
#define WM_SW_SHUTDOWN              WM_SW_API_BASE + 0x04

// command APIs
#define WM_SW_INIT                  WM_SW_API_BASE + 0x10
#define WM_SW_ACTIVATE              WM_SW_API_BASE + 0x11
#define WM_SW_LOCK                  WM_SW_API_BASE + 0x12
#define WM_SW_TRIGGER               WM_SW_API_BASE + 0x13
#define WM_SW_GET_STATUS            WM_SW_API_BASE + 0x14

// configuration API
#define CD_SW_SET_PARAMETER         WM_SW_API_BASE + 0x20

// buffered data API
#define WM_SUPERWEDGE_BUFFER_READY  WM_SW_API_BASE + 0x30


//
// Define class name and window text used when calling FindWindow to connect
// with SuperWedge
//
#define SW_CLASSNAME                _T("SuperWedge")
#define SW_WINDOWTEXT               _T("SuperWedgeDialog")

//
// Define the string used to perform default all reset which sets all INI 
// parameters to their factory defaults
//
#define SW_DEFAULTALL               "defaultall\r\n"

/////////////////////
//                 //
// Connection APIs //
//                 //
/////////////////////

//
// SWRegisterClient
//
// Description: Register client window handle with SuperWedge. Called to 
//              connect with SuperWedge for performing API calls.
//
//  In:     hClientWnd      - client window handle
//          hSuperWedgeWnd  - variable to receive SuperWedge window handle
//          lResult         - variable to receive API call result
//
//  Out:    lResult         - ERROR_SUCCESS indicates success
//                            ERROR_FAILURE indicates failure
//          hSuperWedgeWnd  - if ERROR_SUCCESS retrieved SuperWedge window
//                            handle
//          
#define SWRegisterClient(hClientWnd, hSuperWedgeWnd, lResult) \
            if ((hSuperWedgeWnd = ::FindWindow(SW_CLASSNAME, SW_WINDOWTEXT))!= NULL){ \
               lResult=::SendMessage(hSuperWedgeWnd, WM_SW_REGISTERCLIENT,(WPARAM)hClientWnd,0); \
            }

//
// SWDeRegisterClient
//
// Description: Deregister client window handle with SuperWedge.  Called to
//              disconnect from SuperWedge.
//
//  In:     hClientWnd      - client window handle
//          hSuperWedgeWnd  - SuperWedge window handle
//          lResult         - variable to receive API call result
//
//  Out:    lResult         - ERROR_SUCCESS indicates success
//                            ERROR_FAILURE indicates failure
//
#define SWDeRegisterClient(hClientWnd, hSuperWedgeWnd, lResult) \
            lResult=::SendMessage(hSuperWedgeWnd, WM_SW_DEREGISTERCLIENT,(WPARAM)hClientWnd,0)

//
// SWGetVersion
//
// Description: Retrieve SuperWedge version.  Called to determine 
//              SuperWedge version.  SuperWedge versions starting at v2.000
//              support the API calls.
//
//  In:     hSuperWedgeWnd  - SuperWedge window handle
//          dwVersion       - variable to receive version number
//          lResult         - variable to receive API call result
//
//  Out:    lResult         - ERROR_SUCCESS indicates success
//                            ERROR_FAILURE indicates failure
//          dwVersion       - if ERROR_SUCCESS, retrieved SuperWedge version
//                            number
//
//          Note: the version number is returned as a hexadecimal number 
//                format: <major version>.<minor version>
//                Example:  0x2003 : major version = 2, minor version = 003
//
#define SWGetVersion(hSuperWedgeWnd,dwVersion,lResult) \
            lResult=::SendMessage(hSuperWedgeWnd, WM_SW_GET_VERSION, 0,0); \
            if (lResult != ERROR_SERVICE_DOES_NOT_EXIST)  { \
                dwVersion = lResult; \
                lResult = ERROR_SUCCESS; \
            }

//
// SWSetBufferedMode
//
// Description: Enable or disable SuperWedge buffered mode operation.  
//
//  In:     hClientWnd      - client window handle
//          bBuffered       - buffered mode setting; 
//                            TRUE=buffered mode, 
//                            FALSE=non-buffered (wedge) mode
//          lResult         - variable to receive API call result
//
//  Out:    lResult         - ERROR_SUCCESS indicates success
//                            ERROR_FAILURE indicates failure
//
#define SWSetBufferedMode(hSuperWedgeWnd, bBuffered, lResult) \
            lResult=::SendMessage(hSuperWedgeWnd, WM_SW_BUFFERED_MODE, (WPARAM)bBuffered, 0);

//
// SWInitialize
//
// Description: Initialize SuperWedge.  Called to reset SuperWedge to the
//              INI file settings.  
//
//  In:     hClientWnd      - client window handle
//          lResult         - variable to receive API call result
//
//  Out:    lResult         - ERROR_SUCCESS indicates success
//                            ERROR_FAILURE indicates failure
//
//  Note:   This function duplicates the Initialize selection on the 
//          SuperWedge taskbar menu.  It is not a required call for API 
//          operation.
//
#define SWInitialize(hSuperWedgeWnd, lResult) \
            lResult=::SendMessage(hSuperWedgeWnd, WM_SW_INIT, 0, 0)


//
// SWExit
//
// Description:  Call to direct SuperWedge to shutdown. This function will
//               replicate the functionality provided by the SuperWedge Dialog
//               Box Close menu option.
//
//  In:     hClientWnd      - client window handle
//          lResult         - variable to receive API call result
//
//  Out:    lResult         - ERROR_SUCCESS indicates success 
//                            ERROR_FAILURE indicates failure
//
//  Note:   Failure may result from no registered client.
//
#define SWExit(hSuperWedgeWnd, lResult) \
            lResult=::SendMessage(hSuperWedgeWnd, WM_SW_SHUTDOWN, 0, 0)


//////////////////
//              //
// Command APIs //
//              //
//////////////////


//
// SWSetActive
//
// Description: Set SuperWedge active state.  Called to activate or deactivate
//              SuperWedge operation.  
//
//  In:     hClientWnd      - client window handle
//          bActivate       - active state setting; 
//                            TRUE=active, 
//                            FALSE=inactive
//          lResult         - variable to receive API call result
//
//  Out:    lResult         - ERROR_SUCCESS indicates success
//                            ERROR_FAILURE indicates failure
//
//  Note:   This function duplicates the Enable selection on the SuperWedge 
//          taskbar menu
//
#define SWSetActive(hSuperWedgeWnd, bActivate, lResult) \
            lResult=::SendMessage(hSuperWedgeWnd, WM_SW_ACTIVATE, (WPARAM)bActivate, 0)

//
// SWSetLock
//
// Description: Set SuperWedge lock state.  Called to lock or unlock 
//              SuperWedge operation.  
//
//  In:     hClientWnd      - client window handle
//          bLock           - lock state setting; 
//                            TRUE=locked, 
//                            FALSE=unlocked
//          lResult         - variable to receive API call result
//
//  Out:    lResult         - ERROR_SUCCESS indicates success
//                            ERROR_FAILURE indicates failure
//
//  Note:   This function duplicates the Lock selection on the SuperWedge
//          taskbar menu
//
#define SWSetLock(hSuperWedgeWnd, bLock, lResult)  \
            lResult=::SendMessage( hSuperWedgeWnd, WM_SW_LOCK, (WPARAM)bLock, 0)

//
// SWSetTrigger
//
// Description: Set SuperWedge trigger state.  Called to pull or release the 
//              SuperWedge trigger.  
//
//  In:     hClientWnd      - client window handle
//          bOnOff          - trigger setting; TRUE=pull, FALSE=release
//          lResult         - variable to receive API call result
//
//  Out:    lResult         - ERROR_SUCCESS indicates success
//                            ERROR_FAILURE indicates failure
//
#define SWSetTrigger(hSuperWedgeWnd, bOnOff, lResult) \
            lResult=::SendMessage( hSuperWedgeWnd, WM_SW_TRIGGER, (WPARAM)bOnOff, 0 )


////////////////////////
//                    //
// Configuration APIs //
//                    //
////////////////////////

//
// SWSetParameter
//
// Description: Set SuperWedge parameter setting(s).  Called to update one or 
//              many parameter settings.  
//
//  In:     hClientWnd      - client window handle
//          lpSetting       - ASCII string of parameter settings
//          lResult         - variable to receive API call result
//
//  Out:    lResult         - ERROR_SUCCESS indicates success
//                            Non-zero indicates error.  The low word of
//                            lResult indicates the line number of the first
//                            line with an error.  The high word of lResult
//                            indicates the argument that causes the error.
//                            Apps can then call GetLastError() to determine 
//                            the type of error that occurred.
//  Note: lpSetting points to an ASCII string which contains a single or 
//        multiple parameter settings separated by carriage return and line 
//        feed characters.  The ASCII string may contain any of the parameters
//        described in the Wedge Configuration Template File Design 
//        specification.  The ASCII string may also contain the "defaultall" 
//        indicator that directs SuperWedge to reset all settings to their 
//        factory defaults prior to any settings following in the string.
//
//      Example:   CHAR ucStartingSetup[]="defaultall\r\nAim Dot=1,10\r\nAuxPort=1\r\n\0";
//
#define SWSetParameter(hSuperWedgeWnd, lpSetting, lResult) \
            { \
            COPYDATASTRUCT   cdsCD; \
            cdsCD.dwData   = CD_SW_SET_PARAMETER; \
            cdsCD.cbData   = strlen((CONST char *)lpSetting);\
            cdsCD.lpData   = (PVOID)lpSetting;\
            lResult=::SendMessage(hSuperWedgeWnd, WM_COPYDATA,(WPARAM)hSuperWedgeWnd, (LPARAM)&cdsCD);\
            }

//
// SWGetStatus
//
// Description:   Retrieves the current status of all SuperWedge parameters.  
//                Parameters are returned via the wedge interface or previously
//                set buffer.  Syntax is identical to the initialization INI 
//                file.
//
//  In:     hClientWnd      - client window handle
//          lResult         - variable to receive API call result
//
//  Out:    lResult         - ERROR_SUCCESS indicates success
//                            ERROR_FAILURE indicates failure
//
#define SWGetStatus(hSuperWedgeWnd, lResult) \
            lResult=::SendMessage( hSuperWedgeWnd, WM_SW_GET_STATUS, 0, 0 )


////////////////////////////////////////
//                                    //
// WM_SUPERWEDGE_BUFFER_READY defines //
//                                    //
////////////////////////////////////////

//
// Data buffer of decoded SuperWedge data provided by the 
// WM_SUPERWEDGE_BUFFER_READY Windows Message, 
// The buffer is pointed to by the wParam parameter, lParam is not used.
//
// Note: The wFlag member of the buffer will be set to TRUE when the message 
//       is posted.  The receiver must clear wFlag once the data have been 
//       received.

typedef struct BUFFERED_SUPERWEDGE_DATA_S 
   {
      WORD        wFlag;          // TRUE = unread data, FALSE = read data
      WORD        wDataType;      // Symbology/Data source
      WORD        wCount;         // Count of characters placed in data buffer
      WORD        wData[4096];    // SuperWedge data buffer
   } BUFFERED_SUPERWEDGE_DATA, *PSWBUF;

#define SWBUF                           BUFFERED_SUPERWEDGE_DATA

// values for wFlag
#define SW_DATABUFFER_FREE              FALSE
#define SW_DATABUFFER_BUSY              TRUE

// values for wDataType
#define SW_DATATYPE_NONE                0x00
#define SW_DATATYPE_CODE39              0x01
#define SW_DATATYPE_CODABAR             0x02
#define SW_DATATYPE_CODE128             0x03
#define SW_DATATYPE_D2OF5               0x04

#define SW_DATATYPE_IATA25              0x05
#define SW_DATATYPE_I2OF5               0x06
#define SW_DATATYPE_CODE93              0x07
#define SW_DATATYPE_UPCA                0x08
#define SW_DATATYPE_UPCE                0x09

#define SW_DATATYPE_EAN8                0x0A
#define SW_DATATYPE_EAN13               0x0B
#define SW_DATATYPE_CODE11              0x0C
#define SW_DATATYPE_MSI_PLESSEY         0x0E
#define SW_DATATYPE_EAN128              0x0F

#define SW_DATATYPE_UPCE1               0x10
#define SW_DATATYPE_PDF417              0x11
#define SW_DATATYPE_CODE39_FULL_ASCII   0x13
#define SW_DATATYPE_TRIOPTIC            0x15
#define SW_DATATYPE_BOOKLAND            0x16

#define SW_DATATYPE_COUPONCODE          0x17
#define SW_DATATYPE_ISBT128             0x19
#define SW_DATATYPE_MICRO_PDF417        0x1A
#define SW_DATATYPE_DATA_MATRIX         0x1B
#define SW_DATATYPE_CODE32              0x20

#define SW_DATATYPE_ISBT128_CONCAT      0x21
#define SW_DATATYPE_MAXICODE            0x25
#define SW_DATATYPE_RSS_14              0x30
#define SW_DATATYPE_RSS_LIMITED         0x31
#define SW_DATATYPE_RSS_EXPANDED        0x32

#define SW_DATATYPE_UPCA_2              0x48
#define SW_DATATYPE_UPCE_2              0x49
#define SW_DATATYPE_EAN8_2              0x4A
#define SW_DATATYPE_EAN13_2             0x4B
#define SW_DATATYPE_UPCE1_2             0x50

#define SW_DATATYPE_CCA_EAN128          0x51    // Composite Code A
#define SW_DATATYPE_CCA_EAN13           0x52
#define SW_DATATYPE_CCA_EAN8            0x53
#define SW_DATATYPE_CCA_RSS_EXPANDED    0x54
#define SW_DATATYPE_CCA_RSS_LIMITED     0x55

#define SW_DATATYPE_CCA_RSS_14          0x56
#define SW_DATATYPE_CCA_UPCA            0x57
#define SW_DATATYPE_CCA_UPCE            0x58
#define SW_DATATYPE_CCC_EAN128          0x59    // Composite Code C
#define SW_DATATYPE_TLC39               0x5A

#define SW_DATATYPE_CCB_EAN128          0x61    // Composite Code B
#define SW_DATATYPE_CCB_EAN13           0x62
#define SW_DATATYPE_CCB_EAN8            0x63
#define SW_DATATYPE_CCB_RSS_EXPANDED    0x64
#define SW_DATATYPE_CCB_RSS_LIMITED     0x65

#define SW_DATATYPE_CCB_RSS_14          0x66
#define SW_DATATYPE_CCB_UPCA            0x67
#define SW_DATATYPE_CCB_UPCE            0x68
#define SW_DATATYPE_UPCA_5              0x88
#define SW_DATATYPE_UPCE_5              0x89

#define SW_DATATYPE_EAN8_5              0x8A
#define SW_DATATYPE_EAN13_5             0x8B
#define SW_DATATYPE_UPCE1_5             0x90

#define SW_DATATYPE_VIN                 0xC0
#define SW_DATATYPE_AZTEC               0xC1
#define SW_DATATYPE_CODE16K             0xC2
#define SW_DATATYPE_CODE49              0xC3

#define SW_DATATYPE_AUXPORT             0x100
#define SW_DATATYPE_MSR                 (SW_DATATYPE_AUXPORT + 1)


// special data types

// used in Edit declaration to indicate the edit applies to data from any 
// input source
#define SW_DATATYPE_ANY                 0xA000

// used in Edit declaration to indicate the edit applies to data of any 
// decoded symbology
#define SW_DATATYPE_SCANNER             (SW_DATATYPE_ANY+1)

// indicates data is a message from SuperWedge rather than data from an 
// input source
#define SW_DATATYPE_MSG                 0xF000 


#endif SWAPI_H_DEFINED

