I'm creating a .NET Windows service to communicate with a smart card reader. The maincomponent is a Windows DLL called winscard.dll which I'm using with DLLImport attribute in the .NET code. Everything works fine on Windows XP 32 bit, but when i running it on Windows 7 x64 i recive 0x6 ERROR_INVALID_HANDLE result when calling SCardTransmit. The application (the service as command line app) can connect to the card reader but cannot read anything from the card.
Any idea?
You have problems with SCardEstablishContext it will return 0 but handle also 0. Use IntPtr instead of Integer:
phContext will be store valid value in Windows x64 (Windows 8 x64 and Windows 2008 via RDP tested). Also replace other "Integer" to "IntPtr" when it used as handle.