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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:37:52+00:00 2026-06-13T17:37:52+00:00

I want to implement a Mongoose (http://code.google.com/p/mongoose/) Binding in C#. There are some examples,

  • 0

I want to implement a Mongoose (http://code.google.com/p/mongoose/) Binding in C#. There are some examples, but they don’t work with the current version.

This is my current function call:

[DllImport("_mongoose",CallingConvention=CallingConvention.Cdecl)] private static extern IntPtr mg_start(int zero, Nullable, string options);

The (working) C equivalent would be:

const char *options[] = {
     "document_root", "/var/www",
     "listening_ports", "80,443s",
     NULL
   };
struct mg_context *ctx = mg_start(&my_func, NULL, options);

where mg_start is defined as:

struct mg_context *mg_start(mg_callback_t callback, void *user_data,
                            const char **options);

You can find the whole C example here:
https://svn.apache.org/repos/asf/incubator/celix/trunk/remote_services/remote_service_admin_http/private/include/mongoose.h

How do I transfer the const char *options[] to c#?

Thank you

  • 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-13T17:37:53+00:00Added an answer on June 13, 2026 at 5:37 pm
    DllImport("_mongoose",CallingConvention=CallingConvention.Cdecl)]
    private static extern IntPtr mg_start(IntPtr callback, IntPtr userData,
        [In][MarshalAsAttribute(UnmanagedType.LPArray,
                                ArraySubType=UnmanagedType.LPStr)] string[] options);
    

    Haven’t tried this, but I think this gets you there. You might need to make the ArraySubType be LPWStr if you want unicode in the C call. Making it LPStr gives you ANSI.

    Are you doing the function pointers? That’s where the real challenge is. Not so much from declaring and marshaling but rather from a pointer lifespan issue. If mg_start holds onto the unmanaged version of the delegate, you may find that the thunk gets garbage collected on you, in spite of what the documentation says. We’ve seen this happen so often that we’ve, where possible, rearchitected the underlying glue to not use that style of code.

    Generally speaking, if the API is a chatty API with tons of callbacks, you’re going to be hosed by the callbacks. You’re better off trying to create a C++/CLI library that implements the API in a far less chatty way with clear managed/unmanaged boundaries.

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

Sidebar

Related Questions

I want to implement the shopping cart by using multidimensional session array but don't
I want to implement this example http://api.geoext.org/1.1/examples/feature-grid.html made of geoext and openlayers, that feature
I want implement in my software solution an VBA editor but in c# 3.0.
I want to implement a simple script to do some boring housekeeping on my
I want to implement an application which will work as a parser. User will
I want implement forward geocoding in my app. But I am not able to
I want to implement basic shopping cart functionality in my Rails app....are there any
I want to implement file upload in RESTful way using openrasta but not able
I want to implement some animation in CSS3 which has an effect like its
I want to implement the Wikitude API in my iPhone Application. But while implementing

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.