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 7721925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:03:26+00:00 2026-06-01T04:03:26+00:00

I am trying to create a C-style DLL interface that takes in an input

  • 0

I am trying to create a C-style DLL interface that takes in an input char * and assigns an output char * after performing some translation operation. The return value of the function is an error code, so it won’t be used to return a char *.

I call the function in this manner:

char* output;
myfunc((char *) input.c_str(), &output);

And the function is defined as:

DLL_EXPORT int myfunc(char* input, char** output)
{
    string translation = translate(input);
    *output = (char *) malloc((translation.length()+1)*sizeof(char));
    strcpy(*output,(char *) translation.c_str());
}

Is this a correct way of implementing this? Am I creating a memory leak?

  • 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-06-01T04:03:27+00:00Added an answer on June 1, 2026 at 4:03 am

    It’s correct, but you also need to provide another DLL function that will free the memory. You cannot assume that the executable which has loaded your DLL is using the same version of the C runtime library, so if it tries to call free on the returned memory, you might end up corrupting your heap due to differences in the malloc/free implementations in the different runtimes.

    Your API should look something like this:

    DLL_EXPORT int myfunc(char* input, char** output)
    {
        ...
        *output = malloc(...);
        ...
    }
    
    DLL_EXPORT void myfunc_free(char *output)
    {
        free(output);
    }
    

    See also allocating and freeing memory across module boundaries.

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

Sidebar

Related Questions

I am trying to create a simple Automator droplet that will take the style.less
I am trying to create a style that makes dates from the last week
I'm trying to create a style in XAML that can be applied to any
I am trying to create a simple style that highlights the focused UI Element
I am trying to create an application that will send out style-heavy emails and
I am trying to create a Silverlight Toggle button style that would flip between
Using Silverlight 4 & WPF 4, I'm trying to create a button style that
I'm trying to create a preferences window. In it I have some checkbox style
I am trying to create a combobox style widget (jquery-ui compatible) andcurrently I am
I am trying create a WCF service that leverages the WPF MediaPlayer on the

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.