What is the size of the memory area pointed to by unsigned char *?

Well, I know that this was asked earlier, but after searching I could not find the correct answer.

I need to convert the buffer (unsigned char *) to base64, the base64 function I use takes as parameters:

void Base64Enc(const unsigned char *src, int srclen, unsigned char *dest)

where int srclenis the length of the string src.

My question is: how do I get the length of my buffer. No, it is not canceled. No, I do not want sizeof(BYTE). I just need to know what to pass as srclen, so I can convert this buffer to base64.

EDIT

Here is the code showing what I'm 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);
    }
}
+3
source share
4 answers

NULL - , - , .

? , .

:

, . -.

, :

unsigned numelem = size / sizeof(unsigned char)

, , sizeof (unsigned char) 1, - , .

" " .

+4

, . C/++ , . , .

, .

+3
if (pBytes = (unsigned char *) GlobalLock(hMem))

hMem . GlobalAlloc() GlobalReAlloc(). . , .

+3

c-style (, NULL). , .

+2

Source: https://habr.com/ru/post/1711127/


All Articles