Ok, I know this has been asked before but after searching I couldn't find a proper answer.
I need to convert a buffer (unsigned char *) to base64, the base64 function I am using takes as paramters:
void Base64Enc(const unsigned char *src, int srclen, unsigned char *dest)
where int srclen
is the length of the src
string.
My question is, how do I get the length of my buffer. No, it's not null terminated. No, I don't want the sizeof(BYTE)
. I just need to know what to pass to as srclen
so i can convert that buffer to base64.
EDIT:
Here's some code showing what I am doing:
unsigned char *pBytes;
unsigned char *B64Encoded;
int b64size = 0;
if (pBytes = (unsigned char *) GlobalLock(hMem))
{
DWORD size = (DWORD)GlobalSize(hMem);
b64size = size / sizeof(unsigned char);
Base64Enc(pBytes, b64size, B64Encoded);
// in this case save the buffer to a file just for testing
if (fp = fopen("ububub.txt", "wb"))
{
printf("data: %s\n", B64Encoded);
fwrite(B64Encoded, strlen(B64Encoded), 1, fp);
fclose(fp);
}
}