From the wincrypt api I am receiving a void* pointing to a char*.
This char* is pointing to the start of a char[]. I am also receiving a void*
pointing to a int with the size of the char*
.
Regarding pvData and cbData I have the following documentation from Microsoft.
Data type of pvData: A pointer to an array of BYTE values. The size of this array is specified in the cbData parameter. Returns a null-terminated Unicode character string that contains the display name for the certificate.
I want to convert this void*
to a std::string
but so far all I am getting when outputting my std::string
is the first character.
I have read: Converting a void* to a std::string but since my void*
is pointing to a char*
instead of std::string
the static_cast
in the accepted answer fails and the returned std::string*
triggers a null pointer exception.
So far I have the following:
// pvData = void* pointing to char*
// cbData = void* pointing to int*
std::string tempName;
tempName.assign(static_cast<char*>(pvData), static_cast<int*>(cbData));
printf("%S \n", pvData); // entire string is shown
printf("%s \n", tempName.c_str()); // only first character is shown
I have also tried
tempName = static_cast<char*>(pvData); // only single character returned
tempName.assign(static_cast<char*>(pvData)); // only single character returned
char* arr = static_cast<char*>(pvData);
std::string tempName(arr); // only single character returned empty with printf must
// use std::cout