You can refer here for smart card return values. And if not listed, you can refer here for system error codes.
The error code 6 is ERROR_INVALID_HANDLE. Try to check your OS (32-bit or 64-bit) and your smart card driver (32-bit or 64-bit). Ensure that they are the same. Also, check that your codes are using the correct variable type.