So I'm using a API for card readers "eVehicle Registration API" which was made by my government. And it's simple to use, but when I call function GetReaderName(0, &name, &size) that will put values in name and size, the cout of name is weird, it prints weird symbols. I googled for a solution and I found it was a null-terminator, but I'm not quite sure if that is a solution, and if it is I don't know how to add null terminator to it. Here is my code:
#include <eVehicleRegistrationAPI.h>
#include <iostream>
void readDataFromCard() {
auto status = sdStartup(0);
std::cout << status << std::endl;
std::cin.get();
//name variable. Is this right way to do it?
char name;
long size;
//initializing data to variables.
GetReaderName(0, &name, &size);
//printing name. but in my case, it's not working.
std::cout << name << std::endl;
std::cin.get();
//SelectReader(name);
//sdProcessNewCard();
//SD_DOCUMENT_DATA sd_document_data;
//sdReadDocumentData(&sd_document_data);
}
int main() {
readDataFromCard();
return 0;
}
You need to create an array of sufficient size to hold all the characters (plus one more for the null terminating character) in the name. For instance:
1) ...
char dest[100] = {0}; //pre-fill the array with zeros (null terminal chars)
//100 is just a value... use whatever the maximum you expect to get + 1 as said already
GetReaderName(0,dest,&size); //hopefully leaves the zeros in place making it work
It's working! Thanks! The error code was 0x80100008 which means "The data buffer to receive returned data is too small for the returned data" SCARD_E_INSUFFICIENT_BUFFER.