Re: SCardGetStatusChange in .NET

From: Pieter Philippaerts (Pieter.nospam_at_mentalis.org)
Date: 11/09/04


Date: Tue, 9 Nov 2004 16:35:53 +0100


"David" <dflores@rochester.rr.com> wrote
> I am trying to use the Smart Card Win32 API in VB.NET, some of the
> simple functions are easy to declare like SCardEstablishContext and
> SCardListReaders, but I am having trouble declaring SCardGetStatusChange
> function and the structure SCARD_READERSTATE that is passed in. Can anyone
> help with me the correct declaration for both?

Yes, SCardGetStatusChange was the one that gave me the most problems too.
Here's my (working) declaration for it:

[DllImport("winscard.dll", CharSet=CharSet.Auto)]
internal static extern int SCardGetStatusChange(int hContext, int dwTimeout,
[In, Out] SCARD_READERSTATE[] rgReaderStates, int cReaders);

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
internal struct SCARD_READERSTATE {
    [MarshalAs(UnmanagedType.LPTStr)]
    public string szReader;
    public IntPtr pvUserData;
    public int dwCurrentState;
    public int dwEventState;
    public int cbAtr;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst=36)]
    public byte[] rgbAtr;
}

In my case, it was the [In, Out] before the rgReaderStates parameter that
finally solved all my problems.

> p.s. Whatever happened to Win32API.txt? How come it was never updated?

There's a community site at http://www.pinvoke.net/ that's essentially
trying to accomplish the same thing.

Regards,
Pieter Philippaerts



Relevant Pages

  • Re: Do we have extention properties in C# 3.0?
    ... How should the syntax be to distinguish between ... public int MyProperty(this SomeClass arg0) ... No doubt there are other valid ways to allow the declaration of an extension property, but the above seems most straightforward and consistent to me. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Do we have extention properties in C# 3.0?
    ... Peter Duniho wrote: ... public int MyProperty(this SomeClass arg0) ... No doubt there are other valid ways to allow the declaration of an extension property, but the above seems most straightforward and consistent to me. ...
    (microsoft.public.dotnet.languages.csharp)