Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 260743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:22:25+00:00 2026-05-11T22:22:25+00:00

Ok, I know this has been asked before but after searching I couldn’t find

  • 0

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);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:22:25+00:00Added an answer on May 11, 2026 at 10:22 pm

    If it’s not NULL terminated or something-terminated, the only way to know the size is to keep track of it when you first got it.

    How are you getting the buffer in the first place? Whatever that is probably gives you a method of also obtaining the length of the buffer.

    EDIT

    Your comment:

    I have the size of the memory that the
    data takes. I tried playing with that
    but it’s not the correct information
    apparently.

    In that case, take your raw size and divide it by the size of each element to get the number of elements:

    unsigned numelem = size / sizeof(unsigned char)
    

    Thanks to Todd Gardner for pointing out that sizeof(unsigned char) is defined by the standard to be 1, so the number of elements in your buffer is just the amount of space your buffer uses.

    The "divide by size of element" is the more general solution to any type of element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been asked before, but I ran into a problem.
I know this specific question has been asked before , but I am not
I know this question has been asked a bit before. But looking around I
I don't know if this has been asked before, but what i'd like to
I know this question has been asked in several variations before, but my question
I know this question has been asked in a similar fashion before, but I
I'm sorry if this question has been asked before, but I'm not even sure
I know this has been asked a million times, but I haven't had much
I know this has been discussed many times, but I am not sure I
I know this questions has come up in various guises before, but this is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.