typedef struct {
LPCTSTR szReader;
LPVOID pvUserData;
DWORD dwCurrentState;
DWORD dwEventState;
DWORD cbAtr;
BYTE rgbAtr[36];
} SCARD_READERSTATE, *PSCARD_READERSTATE, *LPSCARD_READERSTATE;
I've been searching the web for help on this and all the things I've tried have failed in some form or other. I have got it working in the desktop environment, but that's because complex structs are handle automatically(ish). szReader is known, because it is the name of the reader to be monitored and you pass this to the function.
For the desktop environment the main parts of the code are as follows:
[DllImport("winscard.dll", SetLastError = true)]
internal static extern int SCardGetStatusChange(UInt32 hContext,
UInt32 dwTimeout,
[In,Out] SCard_ReaderState[] rgReaderStates,
UInt32 cReaders);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct SCard_ReaderState
{
public string szReader;
public IntPtr pvUserData;
public UInt32 dwCurrentState;
public UInt32 dwEventState;
public UInt32 cbAtr;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=36)]
public byte[] rgbAtr;
}
SCardGetStatusChange(hContext, WAIT_TIME, readerState, nbReaders);