// scardssp.idl : IDL source for scardssp.dll
//

// This file will be processed by the MIDL tool to
// produce the type library (scardssp.tlb) and marshalling code.

cpp_quote("//+-------------------------------------------------------------------------")
cpp_quote("//")
cpp_quote("//  Microsoft Smart Card Support")
cpp_quote("//  Copyright (C) Microsoft Corporation, 1996 - 1999")
cpp_quote("//")
cpp_quote("//")
cpp_quote("// File: scardssp.h")
cpp_quote("//")
cpp_quote("//--------------------------------------------------------------------------")

cpp_quote("")
cpp_quote("//////////////////////////////////////////////////////////////////")
cpp_quote("//")
cpp_quote("// Imports")
cpp_quote("//")

#ifndef DO_NO_IMPORTS
    import "oaidl.idl";
    import "ocidl.idl";
#endif


cpp_quote("")
cpp_quote("//////////////////////////////////////////////////////////////////")
cpp_quote("//")
cpp_quote("// Interface declarations")
cpp_quote("//")

interface IByteBuffer;
interface ISCardTypeConv;
interface ISCardCmd;
interface ISCardISO7816;
interface ISCard;
interface ISCardDatabase;
interface ISCardLocate;


cpp_quote("")
cpp_quote("//////////////////////////////////////////////////////////////////")
cpp_quote("//")
cpp_quote("// Types and Constants")
cpp_quote("//")

cpp_quote("#ifndef _NULL_DEFINED")
    cpp_quote("#define _NULL_DEFINED")
    #define NULL    0
cpp_quote("#endif // !_NULL_DEFINED")

cpp_quote("#ifndef _BYTE_DEFINED")
    cpp_quote("#define _BYTE_DEFINED")
    typedef [public] unsigned char BYTE;
cpp_quote("#endif // !_BYTE_DEFINED")

cpp_quote("#ifndef _LPBYTE_DEFINED")
    cpp_quote("#define _LPBYTE_DEFINED")
    typedef [public] BYTE *LPBYTE;
cpp_quote("#endif // !_LPBYTE_DEFINED")

cpp_quote("#ifndef _LPCBYTE_DEFINED")
    cpp_quote("#define _LPCBYTE_DEFINED")
    typedef [public] const BYTE *LPCBYTE;
cpp_quote("#endif // !_LPCBYTE_DEFINED")

cpp_quote("#ifndef _HSCARD_DEFINED")
    cpp_quote("#define _HSCARD_DEFINED")
    typedef [public] ULONG_PTR HSCARD;
cpp_quote("#endif // !_HSCARD_DEFINED")

cpp_quote("#ifndef _LPHSCARD_DEFINED")
    cpp_quote("#define _LPHSCARD_DEFINED")
    typedef [unique] HSCARD *PHSCARD;
    typedef [unique] HSCARD *LPHSCARD;
cpp_quote("#endif // !_LPHSCARD_DEFINED")

cpp_quote("#ifndef _HSCARDCONTEXT_DEFINED")
    cpp_quote("#define _HSCARDCONTEXT_DEFINED")
    typedef [public] ULONG_PTR HSCARDCONTEXT;
cpp_quote("#endif // !_HSCARDCONTEXT_DEFINED")

cpp_quote("#ifndef _LPHSCARDCONTEXT_DEFINED")
    cpp_quote("#define _LPHSCARDCONTEXT_DEFINED")
    typedef [unique] SHCARDCONTEXT *PHSCARDCONTEXT;
    typedef [unique] SHCARDCONTEXT *LPHSCARDCONTEXT;
cpp_quote("#endif // !_LPHSCARDCONTEXT_DEFINED")

cpp_quote("#ifndef _BYTEARRAY_DEFINED")
    cpp_quote("#define _BYTEARRAY_DEFINED")
    typedef [helpstring("Helpful byte array."),
             //uuid(),
             //helpcontext(),
             version(1.0)]
    struct tagBYTEARRAY {
        HGLOBAL hMem;
        DWORD dwSize;
        [size_is(dwSize)] LPBYTE pbyData;
     } BYTEARRAY;

    cpp_quote("#define _CB_BYTEARRAY_DEFINED")
    cpp_quote("#define CB_BYTEARRAY (sizeof(BYTEARRAY))")

    cpp_quote("#define _PBYTEARRAY_DEFINED")
    typedef [public] BYTEARRAY *PBYTEARRAY;

    cpp_quote("#define _PCBYTEARRAY_DEFINED")
    typedef [public] const BYTEARRAY *PCBYTEARRAY;

    cpp_quote("#define _LPBYTEARRAY_DEFINED")
    typedef [public] BYTEARRAY *LPBYTEARRAY;

    cpp_quote("#define _LPCBYTEARRAY_DEFINED")
    typedef [public] const BYTEARRAY *LPCBYTEARRAY;
cpp_quote("#endif // _BYTEARRAY_DEFINED")

cpp_quote("#ifndef _STATSTRUCT")
    cpp_quote("#define _STATSTRUCT")
    typedef [helpstring("Stream status structure."),
             //uuid(),
             //helpcontext(),
             version(1.0)]
    struct tagSTATSTRUCT {
        LONG        type;
        LONG        cbSize;
        LONG        grfMode;
        LONG        grfLocksSupported;
        LONG        grfStateBits;
     } STATSTRUCT;

    cpp_quote("#define _CB_STATSTRUCT_DEFINED")
    cpp_quote("#define CB_STATSTRUCT    (sizeof(STATSTRUCT))")

    cpp_quote("#define _LPSTATSTRUCT_DEFINED")
    typedef [public] STATSTRUCT* LPSTATSTRUCT;
cpp_quote("#endif // _STATSTRUCT_DEFINED")

cpp_quote("#ifndef _ISO_APDU_TYPE")
    cpp_quote("#define _ISO_APDU_TYPE")
    typedef [helpstring("ISO 7816-4 APDU Case types."),
             //uuid(),
             //helpcontext(),
             version(1.0)]
    enum tagISO_APDU_TYPE {
        ISO_CASE_1 = 1,
        ISO_CASE_2 = 2,
        ISO_CASE_3 = 3,
        ISO_CASE_4 = 4
    } ISO_APDU_TYPE;
cpp_quote("#endif // _ISO_APDU_TYPE")

cpp_quote("#ifndef _SCARD_SHARE_MODES_DEFINED")
    cpp_quote("#define _SCARD_SHARE_MODES_DEFINED")
    typedef [helpstring("SCard Share Modes"),
             //uuid(),
             //helpcontext(),
             v1_enum,   // force 32-bit transmission over RPC, if in use...
             version(1.0)]
    enum tagSCARD_SHARE_MODES {
        EXCLUSIVE = 1,
        SHARED = 2
     } SCARD_SHARE_MODES;
cpp_quote("#endif // !_SCARD_SHARE_MODES_DEFINED")

cpp_quote("#ifndef _SCARD_DISPOSITIONS_DEFINED")
    cpp_quote("#define _SCARD_DISPOSITIONS_DEFINED")
    typedef [helpstring("SCard Dispositions"),
             //uuid(),
             //helpcontext(),
             v1_enum,   // force 32-bit transmission over RPC, if in use...
             version(1.0)]
    enum tagSCARD_DISPOSITIONS {
        LEAVE = 0,
        RESET = 1,
        UNPOWER = 2,
        EJECT = 3
     } SCARD_DISPOSITIONS;
cpp_quote("#endif // !_SCARD_DISPOSITIONS_DEFINED")

cpp_quote("#ifndef _SCARD_STATES_DEFINED")
    cpp_quote("#define _SCARD_STATES_DEFINED")
    typedef [helpstring("SCard States"),
             //uuid(),
             //helpcontext(),
             v1_enum,   // force 32-bit transmission over RPC, if in use...
             version(1.0)]
    enum tagSCARD_STATES {
        ABSENT = 1,
        PRESENT = 2,
        SWALLOWED = 3,
        POWERED = 4,
        NEGOTIABLEMODE = 5,
        SPECIFICMODE = 6
     } SCARD_STATES;
cpp_quote("#endif // !_SCARD_STATES_DEFINED")

cpp_quote("#ifndef _SCARD_PROTOCOLS_DEFINED")
    cpp_quote("#define _SCARD_PROTOCOLS_DEFINED")
    typedef [helpstring("SCard Protocols"),
             //uuid(),
             //helpcontext(),
             v1_enum,   // force 32-bit transmission over RPC, if in use...
             version(1.0)]
    enum tagSCARD_PROTOCOLS {
        T0 = 0x01,  // T=0 is the active protocol.
        T1 = 0x02,  // T=1 is the active protocol.
        RAW = 0xff  // Raw is the active protocol.
     } SCARD_PROTOCOLS;
cpp_quote("#endif // !_SCARD_PROTOCOLS_DEFINED")

cpp_quote("#ifndef _SCARD_INFO")
    cpp_quote("#define _SCARD_INFO")
    typedef [helpstring("FindCard returned information structure."),
             //uuid(),
             //helpcontext(),
             version(1.0)]
    struct tagSCARDINFO {
        HSCARD  hCard;
        HSCARDCONTEXT hContext;
        SCARD_PROTOCOLS ActiveProtocol;
        SCARD_SHARE_MODES ShareMode;
        LONG_PTR hwndOwner;
        LONG_PTR lpfnConnectProc;
        LONG_PTR lpfnCheckProc;
        LONG_PTR lpfnDisconnectProc;
        //
        // Do we want to include any of the following???
        //
        //   1. card state (i.e., disposition)
        //   2. process ID, thread ID (...a DWORD)
        //   3. card GUID
        //   4. GUID of class factory
        //
      } SCARDINFO;

    cpp_quote ("#define _LPSCARDINFO")
    typedef [unique] SCARDINFO *PSCARDINFO, *LPSCARDINFO;

cpp_quote ("#endif //_SCARD_INFO")



//
// The following values are merely defined as default states for use
// here in this IDL file. They will NOT be bound into the type library
// for use.
//
// These codes are defined in \\nt\private\ispu\calais\ssps\inc\IsoCodes.h
// for use and redefinition, if wanted, in the sources of the SCardSrv.DLL.
//
//
#define ISO_OPEN_LOGICAL_CHANNEL    (0x00)
#define ISO_CLOSE_LOGICAL_CHANNEL   (0x80)

#define ISO_LOGICAL_CHANNEL_0       (0x00)
#define ISO_LOGICAL_CHANNEL_1       (0x01)
#define ISO_LOGICAL_CHANNEL_2       (0x02)
#define ISO_LOGICAL_CHANNEL_3       (0x03)
//
//


cpp_quote("")
cpp_quote("//////////////////////////////////////////////////////////////////")
cpp_quote("//")
cpp_quote("// IByteBuffer Interface")
cpp_quote("//")

cpp_quote("#ifndef _LPBYTEBUFFER_DEFINED")
cpp_quote("#define _LPBYTEBUFFER_DEFINED")
    [
        object,
        uuid(E126F8FE-A7AF-11D0-B88A-00C04FD424B9),
        // dual,
        helpstring("IByteBuffer Interface"),
        pointer_default(unique)
    ]
    interface IByteBuffer : IDispatch
    {
        // Pointers -
        typedef [unique] IByteBuffer* LPBYTEBUFFER;
        typedef [unique] const IByteBuffer *LPCBYTEBUFFER;

        // Properties -
        [   id(0), propget, hidden,
            helpstring("Returns a pointer to the internal IStream object.")]
            HRESULT Stream( [out, retval] LPSTREAM* ppStream );
        [   id(0), propput, hidden,
            helpstring("Sets the internal IStream pointer.")]
            HRESULT Stream( [in] LPSTREAM pStream );

        // Methods -
        [   id(1),
            helpstring("Creates a new object with its own seek pointer that references the same bytes as the original.")
        ]
        HRESULT Clone([in, out] LPBYTEBUFFER* ppByteBuffer);

        [   id(2),
            helpstring("Ensures that any changes made to an object open in transacted mode are reflected in the parent storage.")
        ]
        HRESULT Commit([in] LONG grfCommitFlags);

        [   id(3),
            helpstring("Copies a specified number of bytes from the current seek pointer in the object to the current seek pointer in another object.")
        ]
        HRESULT CopyTo( [in,out] LPBYTEBUFFER* ppByteBuffer,
                        [in] LONG cb,
                        [in,out, defaultvalue(NULL)] LONG* pcbRead,
                        [in,out, defaultvalue(NULL)] LONG* pcbWritten);

        [   id(4),
            helpstring("Initializes the object. This must be called prior to calling any other methods!")]
        HRESULT Initialize( [in, defaultvalue(1)] LONG lSize,
                            [in, defaultvalue(NULL)] BYTE* pData );

        [   id(5),
            helpstring("Restricts access to a specified range of bytes in the buffer object.")
        ]
        HRESULT LockRegion( [in] LONG libOffset,
                            [in] LONG cb,
                            [in] LONG dwLockType);

        [   id(6),
            helpstring("Reads a specified number of bytes from the buffer object into memory starting at the current seek pointer.")
        ]
        HRESULT Read(   [in,out] BYTE* pByte,
                        [in] LONG cb,
                        [in, out, defaultvalue(NULL)] LONG* pcbRead);

        [   id(7),
            helpstring("Discards all changes that have been made to a transacted stream since the last IByteBuffer::Commit call.")
        ]
        HRESULT Revert ( void );

        [   id(8),
            helpstring("Changes the seek pointer to a new location relative to the beginning of the buffer, to the end of the buffer, or to the current seek pointer.")
        ]
        HRESULT Seek(   [in] LONG dLibMove,
                        [in] LONG dwOrigin,
                        [in,out, defaultvalue(NULL)] LONG* pLibnewPosition);

        [   id(9),
            helpstring("Changes the size of the stream object.")
        ]
        HRESULT SetSize([in] LONG libNewSize);

        [   id(10),
            helpstring("Retrieves the STATSTG structure for this object.")
        ]
        HRESULT Stat(   [in,out] LPSTATSTRUCT pstatstg,
                        [in] LONG grfStatFlag);
        [   id(11),
            helpstring("Removes the access restriction on a range of bytes previously restricted with IByteBuffer::LockRegion.")
        ]
        HRESULT UnlockRegion(   [in] LONG libOffset,
                                [in] LONG cb,
                                [in] LONG dwLockType);
        [   id(12),
            helpstring("Writes a specified number from bytes into the stream object starting at the current seek pointer.")
        ]
        HRESULT Write(  [in,out] BYTE* pByte,
                        [in] LONG cb,
                        [in,out] LONG* pcbWritten);
    };
cpp_quote("#endif //_LPBYTEBUFFER_DEFINED")


cpp_quote("")
cpp_quote("//////////////////////////////////////////////////////////////////")
cpp_quote("//")
cpp_quote("// ISCardTypeConv Interface Definition")
cpp_quote("//")

cpp_quote("#ifndef _LPSCARDTYPECONV_DEFINED")
cpp_quote("#define _LPSCARDTYPECONV_DEFINED")
    [
        object,
        uuid(53B6AA63-3F56-11D0-916B-00AA00C18068),
        // dual,
        helpstring("ISCardTypeConv Interface"),
        pointer_default(unique)
    ]
    interface ISCardTypeConv : IDispatch
    {
        // Pointer(s);

        typedef [unique] ISCardTypeConv *LPSCARDTYPECONV;

        // Methods:

        [id(0), helpstring("Convert an array of bytes to an IByteBuffer")]
        HRESULT ConvertByteArrayToByteBuffer(
                    [in] LPBYTE pbyArray,
                    [in] DWORD dwArraySize,
                    [out,retval] LPBYTEBUFFER *ppbyBuffer);

        [id(1), helpstring("Convert an IByteBuffer to an array of bytes")]
        HRESULT ConvertByteBufferToByteArray(
                    [in] LPBYTEBUFFER pbyBuffer,
                    [out,retval] LPBYTEARRAY *ppArray);

        [id(2), helpstring("Convert an IByteBuffer to a SAFEARRAY(unsigned char)")]
        HRESULT ConvertByteBufferToSafeArray(
                    [in] LPBYTEBUFFER pbyBuffer,
                    [out,retval] LPSAFEARRAY *ppbyArray);

        [id(3), helpstring("Convert a SAFEARRAY(unsigned char) to an IByteBuffer")]
        HRESULT ConvertSafeArrayToByteBuffer(
                    [in] LPSAFEARRAY pbyArray,
                    [out,retval] LPBYTEBUFFER *ppbyBuff);

        [id(4), helpstring("Create an array of bytes")]
        HRESULT CreateByteArray(
                    [in] DWORD dwAllocSize,
                    [out,retval] LPBYTE *ppbyArray);

        [id(5), helpstring("Create an IByteBuffer object")]
        HRESULT CreateByteBuffer(
                    [in] DWORD dwAllocSize,
                    [out,retval] LPBYTEBUFFER *ppbyBuff);

        [id(6), helpstring("Create a SAFEARRAY(unsigned char)")]
        HRESULT CreateSafeArray(
                    [in] UINT nAllocSize,
                    [out,retval] LPSAFEARRAY *ppArray);

        [id(7), helpstring("Free a pointer to the memory block managed by the IStream")]
        HRESULT FreeIStreamMemoryPtr(
                    [in] LPSTREAM pStrm,
                    [in] LPBYTE pMem);

        [id(8), helpstring("Get a pointer to the memory block managed by the IStream")]
        HRESULT GetAtIStreamMemory(
                    [in] LPSTREAM pStrm,
                    [out,retval] LPBYTEARRAY *ppMem);

        [id(9), helpstring("How many bytes are in the given IStream")]
        HRESULT SizeOfIStream(
                    [in] LPSTREAM pStrm,
                    [out,retval] ULARGE_INTEGER* puliSize);
    };
cpp_quote("#endif // _LPSCARDTYPECONV_DEFINED")


cpp_quote("")
cpp_quote("//////////////////////////////////////////////////////////////////")
cpp_quote("//")
cpp_quote("// ISCardCmd Interface Definition")
cpp_quote("//")

cpp_quote("#ifndef _LPSCARDCMD_DEFINED")
cpp_quote("#define _LPSCARDCMD_DEFINED")
    [
        object,
        uuid(D5778AE3-43DE-11D0-9171-00AA00C18068),
        // dual,
        helpstring("ISCardCmd Interface"),
        pointer_default(unique)
    ]
    interface ISCardCmd : IDispatch
    {
        // Pointer(s) -

        typedef [unique] ISCardCmd *LPSCARDCMD;

        // Properties -

        [id(0), propget/*, defaultcollelem*/,
         helpstring("Get the raw ISO 7816 APDU string")]
        HRESULT Apdu([out,retval] LPBYTEBUFFER *ppApdu);

        [id(0), propput/*, defaultcollelem*/,
         helpstring("Copy a new APDU over the current one")]
        HRESULT Apdu([in] LPBYTEBUFFER pApdu);

        [id(1), propget/*, defaultcollelem*/,
         helpstring("Get the byte count (size) of the raw ISO 7816 APDU string")]
        HRESULT ApduLength([out,retval] LONG* plSize);

        [id(2), propget/*, defaultcollelem*/,
         helpstring("Get the raw reply ISO 7816 APDU string")]
        HRESULT ApduReply([out,retval] LPBYTEBUFFER *ppReplyApdu);

        [id(2), propput/*, defaultcollelem*/,
         helpstring("Set the raw reply ISO 7816 APDU string")]
        HRESULT ApduReply([in] LPBYTEBUFFER pReplyApdu);

        [id(3), propget/*, defaultcollelem*/,
         helpstring("Get the byte count (size) of the raw reply ISO 7816 APDU string")]
        HRESULT ApduReplyLength([out,retval] LONG* plSize);

        [id(3), propput/*, defaultcollelem*/,
         helpstring("Set the byte count (size) of the raw reply ISO 7816 APDU string")]
        HRESULT ApduReplyLength([in] LONG lSize);

        [id(4), propget/*, defaultcollelem*/,
         helpstring("Get the current class ID of the ISO 7816 APDU header")]
        HRESULT ClassId([out,retval] BYTE* pbyClass);

        [id(4), propput/*, defaultcollelem*/,
         helpstring("Assign a new class ID in the ISO 7816 APDU header")]
        HRESULT ClassId([in,defaultvalue(0)] BYTE byClass);

        [id(5), propget/*, defaultcollelem*/,
         helpstring("Get the current data portion of the ISO 7816 APDU string")]
        HRESULT Data([out,retval] LPBYTEBUFFER *ppData);

        [id(5), propput/*, defaultcollelem*/,
         helpstring("Assign a new data portion of the ISO 7816 APDU string")]
        HRESULT Data([in] LPBYTEBUFFER pData);

        [id(6), propget/*, defaultcollelem*/,
         helpstring("Get the current instruction ID of the ISO 7816 APDU header")]
        HRESULT InstructionId([out,retval] BYTE* pbyIns);

        [id(6), propput/*, defaultcollelem*/,
         helpstring("Assign a new instruction ID in the ISO 7816 APDU header")]
        HRESULT InstructionId([in] BYTE byIns);

        [id(7), propget/*, defaultcollelem*/,
         helpstring("Get the Le parameter (expected length of reply data) of the ISO 7816 APDU")]
        HRESULT LeField([out,retval] LONG* plSize);

        [id(8), propget/*, defaultcollelem*/,
         helpstring("Get the first parameter of the ISO 7816 APDU header")]
        HRESULT P1([out,retval] BYTE* pbyP1);

        [id(8), propput/*, defaultcollelem*/,
         helpstring("Assign a new first parameter in the ISO 7816 APDU header")]
        HRESULT P1([in] BYTE byP1);

        [id(9), propget/*, defaultcollelem*/,
         helpstring("Get the second parameter of the ISO 7816 APDU header")]
        HRESULT P2([out,retval] BYTE* pbyP2);

        [id(9), propput/*, defaultcollelem*/,
         helpstring("Assign a new second parameter in the ISO 7816 APDU header")]
        HRESULT P2([in] BYTE byP2);

        [id(10), propget/*, defaultcollelem*/,
         helpstring("Get the third parameter of the ISO 7816 APDU header")]
        HRESULT P3([out,retval] BYTE* pbyP3);

        [id(11), propget/*, defaultcollelem*/,
         helpstring("Get the reply status word")]
        HRESULT ReplyStatus([out,retval] LPWORD pwStatus);

        [id(11), propput/*, defaultcollelem*/,
         helpstring("Set (save) the reply status word")]
        HRESULT ReplyStatus([in] WORD wStatus);

        [id(12), propget/*, defaultcollelem*/,
         helpstring("Get the reply status SW1 byte.")]
        HRESULT ReplyStatusSW1([out,retval] BYTE* pbySW1);

        [id(13), propget/*, defaultcollelem*/,
         helpstring("Get the reply status SW2 byte.")]
        HRESULT ReplyStatusSW2([out,retval] BYTE* pbySW2);

        [id(14), propget/*, defaultcollelem*/,
         helpstring("Get the current ISO 7816-4 type of the encapsulated APDU.")]
        HRESULT Type([out,retval] ISO_APDU_TYPE* pType);

        [id(18), propget/*, defaultcollelem*/,
         helpstring("Get the T=1 Node Address")]
        HRESULT Nad([out,retval] BYTE* pbNad);

        [id(18), propput/*, defaultcollelem*/,
         helpstring("Set (save) the T=1 Node Address")]
        HRESULT Nad([in] BYTE bNad);

        [id(19), propget/*, defaultcollelem*/,
         helpstring("Get the T=1 Reply Node Address")]
        HRESULT ReplyNad([out,retval] BYTE* pbNad);

        [id(19), propput/*, defaultcollelem*/,
         helpstring("Set (save) the T=1 Reply Node Address")]
        HRESULT ReplyNad([in] BYTE bNad);

        // Methods -

        [id(15),
         helpstring("Build a valid ISO 7816 APDU string")]
        HRESULT BuildCmd([in] BYTE byClassId,
                         [in] BYTE byInsId,
                         [in,defaultvalue(0)] BYTE byP1,
                         [in,defaultvalue(0)] BYTE byP2,
                         [in,defaultvalue(NULL)] LPBYTEBUFFER pbyData,
                         [in,defaultvalue(NULL)] LONG* plLe);

        [id(16),
         helpstring("Clear the current APDU data")]
        HRESULT Clear(void);

        [id(17),
         helpstring("Encapsulate onother APDU into this one as data")]
        HRESULT Encapsulate([in] LPBYTEBUFFER pApdu,
                            [in] ISO_APDU_TYPE ApduType);

        [id(20), propget/*, defaultcollelem*/,
         helpstring("Get the alternate class ID of the ISO 7816 APDU header")]
        HRESULT AlternateClassId([out,retval] BYTE* pbyClass);

        [id(20), propput/*, defaultcollelem*/,
         helpstring("Assign a new alternate class ID in the ISO 7816 APDU header")]
        HRESULT AlternateClassId([in] BYTE byClass);
    };
cpp_quote("#endif //!_LPSCARDCMD_DEFINED")


cpp_quote("")
cpp_quote("//////////////////////////////////////////////////////////////////")
cpp_quote("//")
cpp_quote("// ISCardISO7816 Interface Definition")
cpp_quote("//")

cpp_quote("#ifndef _LPSCARDISO7816_DEFINED")
cpp_quote("#define _LPSCARDISO7816_DEFINED")
        [
                object,
                uuid(53B6AA68-3F56-11D0-916B-00AA00C18068),
                // dual,
                helpstring("ISCardISO7816 Interface"),
                pointer_default(unique)
        ]
        interface ISCardISO7816 : IDispatch
        {
        // Pointer(s) -

        typedef [unique] ISCardISO7816 *LPSCARDISO;
        typedef [unique] LPSCARDISO LPSCARDISO7816;

        // Methods -

        [id(0),
         helpstring("Write a record to the end of an EF of linear structure of location one of a cyclic structure")]
        HRESULT AppendRecord([in] BYTE byRefCtrl, // currently selected EF
                             [in] LPBYTEBUFFER pData,
                             [in, out] LPSCARDCMD *ppCmd);

        [id(1),
         helpstring("Set part of an EF file content to its erased state sequentially")]
        HRESULT EraseBinary([in] BYTE byP1,
                            [in] BYTE byP2,
                            [in]LPBYTEBUFFER pData,
                            [in, out] LPSCARDCMD *ppCmd);

        [id(2),
         helpstring("Update the card after a GET CHALLENGE command serviced")]
        HRESULT ExternalAuthenticate([in]BYTE byAlgorithmRef,
                                     [in ] BYTE bySecretRef,
                                     [in] LPBYTEBUFFER pChallenge,
                                     [in, out] LPSCARDCMD *ppCmd);

        [id(3),
         helpstring("Issue a challenge for use in a security related procedure")]
        HRESULT GetChallenge([in ] LONG lBytesExpected,
                             [in, out] LPSCARDCMD *ppCmd);

        [id(4),
         helpstring("Retrieve a primitive data object")]
        HRESULT GetData([in] BYTE byP1,
                        [in] BYTE byP2,
                        [in ] LONG lBytesToGet,
                        [in, out] LPSCARDCMD *ppCmd);

        [id(5),
         helpstring("Retrieve further data")]
        HRESULT GetResponse([in ] BYTE byP1, //=0
                            [in] BYTE byP2, //=0
                            [in] LONG lDataLength, // =0
                            [in, out] LPSCARDCMD *ppCmd);

        [id(6),
         helpstring("Compute authentication data on card using challenge data sent to card")]
        HRESULT InternalAuthenticate([in ] BYTE byAlgorithmRef,
                                     [in] BYTE bySecretRef,
                                     [in] LPBYTEBUFFER pChallenge,
                                     [in] LONG lReplyBytes,
                                     [in, out] LPSCARDCMD *ppCmd);

        [id(7),
         helpstring("Open or close a logical channel")]
        HRESULT ManageChannel([in ] BYTE byChannelState,
                              [in] BYTE byChannel,
                              [in, out] LPSCARDCMD *ppCmd);

        [id(8),
         helpstring("Write a primitive data object")]
        HRESULT PutData([in] BYTE byP1,
                        [in] BYTE byP2,
                        [in] LPBYTEBUFFER pData,
                        [in, out] LPSCARDCMD *ppCmd);

        [id(9),
         helpstring("Read part of the content of an EF with transparent structure")]
        HRESULT ReadBinary([in] BYTE byP1,
                           [in] BYTE byP2,
                           [in ] LONG lBytesToRead,
                           [in, out] LPSCARDCMD *ppCmd);

        [id(10),
         helpstring("Read contents of a specified record from an EF")]
        HRESULT ReadRecord([in] BYTE byRecordId, // current record
                           [in] BYTE byRefCtrl,
                           [in] LONG lBytesToRead,
                           [in, out] LPSCARDCMD *ppCmd);

        [id(11),
         helpstring("Set a current file within a logical channel")]
        HRESULT SelectFile([in] BYTE byP1,
                           [in] BYTE byP2,
                           [in ] LPBYTEBUFFER pData,
                           [in ] LONG lBytesToRead,
                           [in, out] LPSCARDCMD *ppCmd);

        [id(12),
         helpstring("Change the default class ID used in command construction")]
        HRESULT SetDefaultClassId([in] BYTE byClass);

        [id(13),
         helpstring("Update bits already present in an EF with command APDU bits")]
        HRESULT UpdateBinary([in] BYTE byP1,
                             [in] BYTE byP2,
                             [in] LPBYTEBUFFER pData,
                             [in, out] LPSCARDCMD *ppCmd);

        [id(14),
         helpstring("Update a specific record with the APDU bits")]
        HRESULT UpdateRecord([in ] BYTE byRecordId, // current record
                             [in] BYTE byRefCtrl, // first record in currently selected EF
                             [in] LPBYTEBUFFER pData,
                             [in, out] LPSCARDCMD *ppCmd);

        [id(15),
         helpstring("Compare the verification data sent to the card with its stored reference data")]
        HRESULT Verify([in] BYTE byRefCtrl, // no info is given
                       [in] LPBYTEBUFFER pData,
                       [in, out] LPSCARDCMD *ppCmd);

        [id(16),
         helpstring("Write binary values into an EF")]
        HRESULT WriteBinary([in] BYTE byP1,
                            [in] BYTE byP2,
                            [in] LPBYTEBUFFER pData,
                            [in, out] LPSCARDCMD *ppCmd);

        [id(17),
         helpstring("Write to the specified record in an EF")]
        HRESULT WriteRecord([in] BYTE byRecordId, // current record
                            [in] BYTE byRefCtrl, // first record in currently selected EF
                            [in] LPBYTEBUFFER pData,
                            [in, out] LPSCARDCMD *ppCmd);
    };
cpp_quote("#endif //!_LPSCARDISO7816_DEFINED")


cpp_quote("")
cpp_quote("//////////////////////////////////////////////////////////////////")
cpp_quote("//")
cpp_quote("// ISCard Interface")
cpp_quote("//")

cpp_quote("#ifndef _LPSCARD_DEFINED")
cpp_quote("#define _LPSCARD_DEFINED")
        [
                object,
                uuid(1461AAC3-6810-11D0-918F-00AA00C18068),
                // dual,
                helpstring("ISCard Interface"),
                pointer_default(unique)
        ]
        interface ISCard : IDispatch
        {
        // Pointer(s) -

        typedef [unique] ISCard* LPSCARD;
        typedef [unique] LPSCARD LPSMARTCARD;

        // Properties -

        [id(0), propget,
         helpstring("Retrieve the ATR string for the Smart Card")]
        HRESULT Atr([out,retval] LPBYTEBUFFER *ppAtr);

        [id(1), propget,
         helpstring("Retrieve the current card handle.")]
        HRESULT CardHandle([out,retval] HSCARD *pHandle);

        [id(2), propget,
         helpstring("Retrieve the current context handle.")]
        HRESULT Context([out,retval] HSCARDCONTEXT *pContext);

        [id(3), propget,
         helpstring("Retrieve the protocol in use on the Smart Card")]
        HRESULT Protocol([out,retval] SCARD_PROTOCOLS *pProtocol);

        [id(4), propget,
         helpstring("Retrieve the current state that the Smart Card is in")]
        HRESULT Status([out,retval] SCARD_STATES *pStatus);

        // Methods -

        [id(5),
         helpstring("Attach an open SCard handle to this object")]
        HRESULT AttachByHandle([in] HSCARD hCard);

        [id(6),
         helpstring("Open a connection to a card in the named reader")]
        HRESULT AttachByReader([in] BSTR bstrReaderName,
                               [in,defaultvalue(EXCLUSIVE)]
                                    SCARD_SHARE_MODES ShareMode,
                               [in,defaultvalue(T0)]
                                    SCARD_PROTOCOLS PrefProtocol);

        [id(7),
         helpstring("Close a connection to an open card")]
        HRESULT Detach([in,defaultvalue(LEAVE)]
                            SCARD_DISPOSITIONS Disposition);

        [id(8),
         helpstring("Acquire exclusive access and use of the open Smart Card")]
        HRESULT LockSCard(void);

        [id(9),
         helpstring("Reattach an existing connection to an in use Smart Card ")]
        HRESULT ReAttach([in,defaultvalue(EXCLUSIVE)]
                                SCARD_SHARE_MODES ShareMode,
                         [in,defaultvalue(LEAVE)]
                                SCARD_DISPOSITIONS InitState);

        [id(10),
         helpstring("Execute a card transaction with a card command interface")]
        HRESULT Transaction([in,out] LPSCARDCMD *ppCmd);

        [id(11),
         helpstring("Release the exclusive access lock on the Smart Card")]
        HRESULT UnlockSCard([in,defaultvalue(LEAVE)]
                            SCARD_DISPOSITIONS Disposition);
    };
cpp_quote("#endif // !_LPSCARD_DEFINED")


cpp_quote("")
cpp_quote("//////////////////////////////////////////////////////////////////")
cpp_quote("//")
cpp_quote("// ISCardDatabase Interface")
cpp_quote("//")

cpp_quote("#ifndef _LPSCARDDATABASE_DEFINED")
cpp_quote("#define _LPSCARDDATABASE_DEFINED")
        [
                object,
                uuid(1461AAC8-6810-11D0-918F-00AA00C18068),
                // dual,
                helpstring("ISCardDatabase Interface"),
                pointer_default(unique)
        ]
        interface ISCardDatabase : IDispatch
        {
        // Pointer(s) -

        typedef [unique] ISCardDatabase* LPSCARDDATABASE;

        // Methods -

        [id(0),
         helpstring("Retrieve the provider ID for the named card")]
        HRESULT GetProviderCardId([in] BSTR bstrCardName,
                                  [out,retval] LPGUID *ppguidProviderId);

        [id(1),
         helpstring("Retrieve a list of the interfaces (GUIDs) for the named card")]
        HRESULT ListCardInterfaces([in] BSTR bstrCardName,
                                   [out,retval] LPSAFEARRAY *ppInterfaceGuids); // BSTR

        [id(2),
         helpstring("Retrieve a list of the names of the defined cards")]
        HRESULT ListCards([in,defaultvalue(NULL)] LPBYTEBUFFER pAtr,
                          [in,defaultvalue(NULL)] LPSAFEARRAY pInterfaceGuids,  // BSTR
                          [in,lcid,defaultvalue(0x0409)] long localeId,
                          [out,retval] LPSAFEARRAY *ppCardNames);                       // BSTR

        [id(3),
         helpstring("Retrieve a list of the names of the defined card reader groups")]
        HRESULT ListReaderGroups([in,lcid,defaultvalue(0x0409)] long localeId,
                                 [out,retval] LPSAFEARRAY *ppReaderGroups);     // BSTR

        [id(4),
         helpstring("Retrieve a list of the names of the defined card readers")]
        HRESULT ListReaders([in,lcid,defaultvalue(0x0409)] long localeId,
                            [out,retval] LPSAFEARRAY *ppReaders);       // BSTR
    };
cpp_quote("#endif // !_LPSCARDDATABASE_DEFINED")


cpp_quote("")
cpp_quote("//////////////////////////////////////////////////////////////////")
cpp_quote("//")
cpp_quote("// ISCardLocate Interface")
cpp_quote("//")

cpp_quote("#ifndef _LPSCARDLOCATE_DEFINED")
cpp_quote("#define _LPSCARDLOCATE_DEFINED")
        [
                object,
                uuid(1461AACD-6810-11D0-918F-00AA00C18068),
                // dual,
                helpstring("ISCardLocate Interface"),
                pointer_default(unique)
        ]
        interface ISCardLocate : IDispatch
        {
        // Pointer(s) -

        typedef [unique] ISCardLocate* LPSCARDLOCATE;
        typedef [unique] LPSCARDLOCATE LPSCARDLOC;

        // Type(s) -

        // Methods -

        [id(0),
         helpstring("Configure the search based on the card GUIDs")]
        HRESULT ConfigureCardGuidSearch(
                        [in] LPSAFEARRAY pCardGuids,                        // BSTR
                        [in,defaultvalue(NULL)] LPSAFEARRAY pGroupNames,    // BSTR
                        [in,defaultvalue("")] BSTR bstrTitle,
                        [in,defaultvalue(1)] LONG lFlags);

        [id(1),
         helpstring("Configure the search based on card names")]
        HRESULT ConfigureCardNameSearch(
                        [in] LPSAFEARRAY pCardNames,                        // BSTR
                        [in,defaultvalue(NULL)] LPSAFEARRAY pGroupNames,    // BSTR
                        [in,defaultvalue("")] BSTR bstrTitle,
                        [in,defaultvalue(1)] LONG lFlags);

        [id(2),
         helpstring("Find and open a connection to the named Smart Card")]
        HRESULT FindCard([in,defaultvalue(EXCLUSIVE)]
                            SCARD_SHARE_MODES ShareMode,
                         [in,defaultvalue(T0)]
                            SCARD_PROTOCOLS Protocols,
                         [in,defaultvalue(1)] LONG lFlags,
                         [out,retval] LPSCARDINFO *ppCardInfo);
    };
cpp_quote("#endif // !_LPSCARDLOCATE_DEFINED")



[
        uuid(82C38704-19F1-11D3-A11F-00C04F79F800),
        version(1.0),
        helpstring("scardssp 1.0 Type Library")
]
library SCARDSSPLib
{
        importlib("stdole32.tlb");
        importlib("stdole2.tlb");

        [
                uuid(E126F8FF-A7AF-11D0-B88A-00C04FD424B9),
                helpstring("ByteBuffer Class")
        ]
        coclass CByteBuffer
        {
                [default] interface IByteBuffer;
        };
        [
                uuid(53B6AA67-3F56-11D0-916B-00AA00C18068),
                helpstring("SCardTypeConv Class")
        ]
        coclass CSCardTypeConv
        {
                [default] interface ISCardTypeConv;
        };
        [
                uuid(D5778AE7-43DE-11D0-9171-00AA00C18068),
                helpstring("SCardCmd Class")
        ]
        coclass CSCardCmd
        {
                [default] interface ISCardCmd;
        };
        [
                uuid(53B6AA6C-3F56-11D0-916B-00AA00C18068),
                helpstring("SCardISO7816 Class")
        ]
        coclass CSCardISO7816
        {
                [default] interface ISCardISO7816;
        };
        [
                uuid(1461AAC7-6810-11D0-918F-00AA00C18068),
                helpstring("SCard Class")
        ]
        coclass CSCard
        {
                [default] interface ISCard;
        };
        [
                uuid(1461AACC-6810-11D0-918F-00AA00C18068),
                helpstring("SCardDatabase Class")
        ]
        coclass CSCardDatabase
        {
                [default] interface ISCardDatabase;
        };
        [
                uuid(1461AAD1-6810-11D0-918F-00AA00C18068),
                helpstring("SCardLocate Class")
        ]
        coclass CSCardLocate
        {
                [default] interface ISCardLocate;
        };
};

