CardReadFile function

The CardReadFile function reads the entire file at the specified location into the user-supplied buffer.


 WINAPI CardReadFile(
  _In_      PCARD_DATA pCardData,
  _In_opt_  LPSTR      pszDirectoryName,
  _In_      LPSTR      pszFileName,
  _In_      DWORD      dwFlags,
  _Out_opt_ PBYTE      ppbData,
  _Out_opt_ PDWORD     pcbData


pCardData [in]

Context information for the call. For more information, see CardAcquireContext.

pszDirectoryName [in, optional]

Name of the directory that contains the file; NULL for root.

pszFileName [in]

File name for the file of interest.

dwFlags [in]

Reserved. Set to 0.

ppbData [out, optional]

Address of a byte pointer to receive the address of a buffer that contains the file contents.

pcbData [out, optional]

Address of a DWORD to receive the byte count of the file contents. On input, the contents of the pointer’s destination should be ignored.

Return value

Zero on success; otherwise, nonzero.


The buffer that contains the returned data is allocated by the card minidriver and freed by the Base CSP/KSP.

For more information, see the comments regarding file sizes in “CardWriteFile” later in this specification.

If pszFileName specifies a nonexistent file, CardReadFile should fail with SCARD_E_FILE_NOT_FOUND.

If CardReadFile is called on a nonexistent directory, an SCARD_E_DIR_NOT_FOUND error code must be returned.

If the name that was specified by pszFileName or pszDirectoryName is longer than the maximum length for file/directory names, SCARD_E_INVALID_PARAMETER must be returned.

When this function is called for the card identifier (cardid) file or cache (cardcf) file, the cache functions in the CARD_DATA structure should not be called. Otherwise, the attempt results in an endless loop.


Target platform



Cardmod.h (include Cardmod.h)

See also




Send comments about this topic to Microsoft