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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:46:06+00:00 2026-06-15T19:46:06+00:00

I have a C library with this function that returns 4 output parameters: void

  • 0

I have a C library with this function that returns 4 output parameters:

void __declspec(dllexport) demofun(double a[], double b[], double* output1, double* output2, double res[], double* output3)

And I wrote a C# wrapper to call the function:

namespace cwrapper
{
    public sealed class CWRAPPER
    {    
        private CWRAPPER() {}

        public static void demofun(double[] a, double[] b, double output1,
                            double output2, double[] res, double output3)
        {   // INPUTS: double[] a, double[] b
            // OUTPUTS: double[] res, double output1, double output2
            // Arrays a, b and res have the same length
            // Debug.Assert(a.length == b.length)

            int length = a.Length;
            CWRAPPERNative.demofun(a, b, length, ref output1, ref output2,
                         res, ref output3);
        }
    }

    [SuppressUnmanagedCodeSecurity]
    internal sealed class CWRAPPERNative
    {
        private CWRAPPERNative() {}

        [DllImport("my_cwrapper.dll", CallingConvention=CallingConvention.Cdecl,
             ExactSpelling=true, SetLastError=false)]
        internal static extern void demofun([In] double[] a, [In] double[] b,
                             int length, ref double output1, ref double output2,
                             [Out] double[] res, ref double output3);
    }
}

Everything works fine when I call the CWRAPPERNative.demofun method. However, when I call the CWRAPPER.demofun method, only the double[] res is passed through correctly. The output parameters output1, output2 and output3 are unchanged after the call.

// ...
// Initializing arrays A and B above here

double[] res = new double[A.Length];
double output1 = 0, output2 = 0, output3 = 0;

// Works partially: output1 to 3 unchanged
CWRAPPER.demofun(A, B, output1, output2, res, output3);

// Works correctly: all outputs are changed
CWRAPPERNative.demofun(A, B, A.Length, ref output1, ref output2, res, ref output3);

I’m guessing that I’m marshalling the pointer arguments wrongly, but I cannot figure out the fix. Anyone knows a solution? Thanks!

  • 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-15T19:46:07+00:00Added an answer on June 15, 2026 at 7:46 pm

    You are forgetting to pass the values by reference inside of demofun:

    public static void demofun(double[] a, double[] b, ref double output1,
       ref double output2, double[] res, ref double output3)
    

    The values is changing inside of the method, but not being modified to the original caller.

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

Sidebar

Related Questions

I have a C++ library with a particular function that returns a boost::any ,
I have function like this: function gi_insert() { if(!IS_AJAX){ $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Naslov', 'trim|required|strip_tags'); $this->form_validation->set_rules('body',
I have a library that has several options defined as this: #define shouldShowToolbar YES
i have a static library which (among other things) implements a tiny function that
I have this JPEG that has been giving problems to the function imagesx($this->image) from
I have this library called BASS which is an audio library which I'm going
I have a library written in C++, and a wrapper for this library written
I have created a static library following this link . But I am facing
I have enabled google Minify in code igniter using this library on our website.
I have a dynamic linked library written in C# 3.0. This library has a

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.