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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:49:18+00:00 2026-05-13T15:49:18+00:00

I tried different things but i’m getting mad with Interop. (here the word string

  • 0

I tried different things but i’m getting mad with Interop.

(here the word string is not referred to a variabile type but “a collection of char”):
I have an unmanaged C++ function, defined in a dll, that i’m trying to access from C#, this function has a string parameter and a string return value like this:

string myFunction(string inputString)
{
}

What should be string in C++ side? and C# one? and what parameters need DllImport for this?

  • 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-13T15:49:18+00:00Added an answer on May 13, 2026 at 3:49 pm

    What I’ve found to work best is to be more explicit about what’s going on here. Having a string as return type is probably not recommended in this situation.

    A common approach is to have the C++ side be passed the buffer and buffer size. If it’s not big enough for what GetString has to put in it, the bufferSize variable is modified to indicate what an appropriate size would be. The calling program (C#) would then increase the size of the buffer to the appropriate size.

    If this is your exported dll function (C++):

    extern "C" __declspec void GetString( char* buffer, int* bufferSize );
    

    Matching C# would be the following:

    void GetString( StringBuilder buffer, ref int bufferSize );
    

    So to use this in C# you would then do something like the following:

    int bufferSize = 512;
    StringBuilder buffer = new StringBuilder( bufferSize );
    GetString( buffer, ref bufferSize );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried a lot of different things but not sure what to do.
How do I use SplitLayoutPanel with UIBinder? I've tried so many different things but
I tried different join types but couldn't figure out which type should I use.
I have searched here on SO and tried different solutions offered here, but cannot
I have tried a bunch of different things but always get syntax errors. I
I've tried many different things but none is working. I have a picture (let
I tried 3 different ways of displaying Page numbers, OnCloseDocument content is not displaying
I've searched and searched and tried many different ways, but I can't seem to
I have searched and tried different things for the past week or so and
I'm so bad at regexp expressions.. I've tried different things and nothing worked. :(

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.