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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:58:25+00:00 2026-06-11T13:58:25+00:00

Im using a C++ Library into a C# solution through the [DllImport(C:\\gaul-windows.dll, …)] attribute.

  • 0

Im using a C++ Library into a C# solution through the
[DllImport("C:\\gaul-windows.dll", ...)] attribute.

I need to use a function which some of its parameters are delegates, and the type it returns also has some delegates as fields.

Can I do this?

Im asking because I tried to do it using the struct as the return type but then I got this exception: “Method’s type signature is not PInvoke compatible”

So I changed it and try using the IntPtr as the return type but then I got this exception: Cannot marshal ‘parameter #16’: Generic types cannot be marshaled.

So first of all I want to know if that is even possible? to use this kind of function that way. If it is not possible how would I be able to use it?

EDIT

Function I need to use


     [DllImport("C:\\gaul-windows.dll",
                 SetLastError = true,
                 CallingConvention = CallingConvention.Cdecl)]
     public extern static IntPtr ga_genesis_boolean(int population_size,
                                                         int num_chromo,
                                                         int len_chromo,
                                                         GAgeneration_hook generation_hook,
                                                         GAiteration_hook iteration_hook,
                                                         GAdata_destructor data_destructor,
                                                         GAdata_ref_incrementor data_ref_incrementor,
                                                         GAevaluate evaluate,
                                                         GAseed seed,
                                                         GAadapt adapt,
                                                         GAselect_one select_one,
                                                         GAselect_two select_two,
                                                         GAmutate mutate,
                                                         GAcrossover crossover,
                                                         GAreplace replace,
                                                         int? userdata);

This is an example of one of the delegates


    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    public delegate short GAselect_one(
        ref population pop,
        IntPtr mother);

Over Here you can get the whole class.

And finally this is my call to the function


    var x = Gaul.ga_genesis_boolean(30,  /* const int              population_size */
                                                  vehicle_num, /* const int              num_chromo */
                                                  order_num,   /* const int              len_chromo */
                                                  IntPtr.Zero,// null,   /* GAgeneration_hook      generation_hook */
                                                  null,   /* GAiteration_hook       iteration_hook */
                                                  null,   /* GAdata_destructor      data_destructor */
                                                  null,   /* GAdata_ref_incrementor data_ref_incrementor */
                                                  new GAevaluate(darp_score),/* GAevaluate           evaluate */
                                                  new GAseed(Gaul.ga_seed_boolean_random), /* GAseed               seed */
                                                  null,     /* GAadapt              adapt */
                                                  new GAselect_one(Gaul.ga_select_one_bestof2),/* GAselect_one     select_one */
                                                  new GAselect_two(Gaul.ga_select_two_bestof2),/* GAselect_two     select_two */
                                                  new GAmutate(Gaul.ga_mutate_boolean_singlepoint),    /* GAmutate        mutate */
                                                  new GAcrossover(Gaul.ga_crossover_boolean_singlepoints), /* GAcrossover     crossover */
                                                  null,          /* GAreplace       replace */
                                                  null          /* vpointer        User data */
                                                  );

  • 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-11T13:58:26+00:00Added an answer on June 11, 2026 at 1:58 pm

    Yes, You can use a C++ Library Function when some of its parameters are delegate.

    The error I was getting “Cannot marshal ‘parameter #16’: Generic types cannot be marshaled.” was not about the delegate parameters but the nullable integer.

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

Sidebar

Related Questions

I have a Matlab function compiled into C library. I am using this library
I would like to add an item into a picture Library using c#. This
I'm using http://pdfobject.com/ jquery library to load the external pdf files into an html
I have refactored some UIView sub-classes into a static library. However, when using Interface
using stdout library it will maybe pass data to logcat or somewhere else which
Am using Mediainfo library in my C# project,before start invoking this dll,i just ran
I'm using a third party library which returns a data reader. I would like
I am using a search library which advises keeping search handle object open for
I have this function in Haskell (I am using the Haskell-SDL library): pixel ::
I have learnt to use library stdarg.h to have function with unknown number of

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.