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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:32:18+00:00 2026-06-02T18:32:18+00:00

I have a C++ DLL which I call from Matlab code using calllib .

  • 0

I have a C++ DLL which I call from Matlab code using calllib.
I have no trouble calling a C++ function which has input parameters only or a function which returns mxArray.

Now I have trouble calling a function which has several output parameters. Let’s say, I need a C++ equivalent of this Matlab function which returns a matrix and an integer.

function [matrix, status] = foo()
status = 42;
matrix = ones(3,2);
end

Whatever I tried, it makes Matlab crash, for example:

DLL_API void foo(mxArray* iop_matrix, int* op_status)
  {
  mxSetM(iop_matrix, 3);
  mxSetN(iop_matrix, 2);
  *op_status = 42;
  }

However I could easily get it to work when I need only one output parameter

DLL_API mxArray* foo(void)
  {
  return mxCreateNumericMatrix(3, 2, mxDOUBLE_CLASS, mxREAL);
  }

What is the correct implementation of such function in C++?

  • 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-02T18:32:19+00:00Added an answer on June 2, 2026 at 6:32 pm

    The Matlab function’s 1st output parameter should be declared as the C function’s output parameter. The Matlab function’s 2nd output parameter should be declared as the C function’s 1st input parameter which has mxArray ** type and so on.

    A C++ function with several output parameters should look like

    mxArray *foo(mxArray **matrix);

    If the function contains input parameters in this case the function is declared as

    mxArray *foo(mxArray **matrix, mxArray *_1stInpParam, mxArray *_2ndInpParam);

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

Sidebar

Related Questions

I have an unmanaged DLL which I'm currently calling from C# using a COM
I have an unmanaged (C/C++) DLL which I need to call from a C#
I have a 3rd party Delphi DLL which I am calling from C++. Unfortunately,
I have a native regular C++ Dll which I want to call from C#
In unmanaged C++ I have a function which I'm trying to call from C#.
I have some COM component which I call from some c# dll. I also
I have a wrapper around a C++ function call which I call from C#
Problem in short: How to call a function from DLL A.dll using p/invoke when
I have a DLL which provided a decoding function, as follows: function MyDecode (Source:
I have a .NET dll which needs to read it's config settings from it's

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.