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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:56:20+00:00 2026-06-12T02:56:20+00:00

I am trying to invoke a function in a C++ DLL from C#/.net. I

  • 0

I am trying to invoke a function in a C++ DLL from C#/.net. I believe there is something wrong with how I am marshaling the data. The function call runs but the return values (the last 7 variables) are all set to 0, and the arrays are set to length of 1 (I assume this is the DLL’s intended behavior when it receives data it can’t work with).

The C++ DLL is compiled as 32bit.

Here is the C++ header:

extern "C" __declspec(dllexport) void __stdcall Merchandize(int SppCode,
                                                                  double DBH, 
                                                                  double TotHt, 
                                                                  double CR, 
                                                                  double BTR,
                                                                  int *minDIBs,     //array
                                                                  int *minLens,     //array
                                                                  int *minVols,     //array
                                                                  int NumProducts, //array length
                                                                  int maxLen,       
                                                                  double trimLen,
                                                                  double stumpHt,
                                                                  int logStep,
                                                                  int *logLens,     //array, understood to be 50
                                                                  double *logSEDs,  //array, understood to be 50
                                                                  double *logVols,  //array, understood to be 50
                                                                  int *logGrades,   //array, understood to be 50
                                                                  int *NumberOfLogs,
                                                                  double *merchHt,
                                                                  int *errorFlag)

And here is the C# dll import:

    [DllImport("C:\\Users\\Public\\Documents\\FVSNEMerchandizer.dll")]
      static extern void MerchandizeTree(int SppCode, 
                                            double DBH,
                                            double TotHt,
                                            double CR,
                                            double BTR,
                                            ref int[] minDIBs,
                                            ref int[] minLens, 
                                            ref int[] minVols, 
                                            int NumProducts,
                                            int maxLen, 
                                            double trimLen, 
                                            double stumpHt, 
                                            int logStep,
                                            ref int[] logLens, 
                                            ref double[] logSEDs, 
                                            ref double[] logVols,
                                            ref int[] logProds, 
                                            ref int[] numLogs, 
                                            ref double merchHt,
                                            ref int errorFlag);
  • 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-12T02:56:21+00:00Added an answer on June 12, 2026 at 2:56 am

    I’m pretty sure you don’t want the ref on the arrays. That would suggest the type in C++ would be int** for instance instead of int*.

    Also, you would probably increase your code’s overall speed if you reduced the number of parameters (by putting them in some sort of struct). The processor has to push a ton of arguments which takes a lot of time when you have that many of them.

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

Sidebar

Related Questions

I am trying to call a Delphi function from C# ASP.NET code. The function's
I'm trying to use P/Invoke to call functions in an unmanaged C++ DLL from
Good day. I'm new to C# and trying to call functions from a DLL
I'm trying to call a Dll function which looks like this (in the C/C++
I'm trying to call SendMessage with an uint parameter from Java, but I can't
I'm trying to call a C function from C#. Here is the function from
I am trying to run the following C function from Java using JNA, but
I want to invoke the following C++ function (exported by a DLL) from C#:
I am trying to call the PrintDlgW Win32 API from C# via P/Invoke. With
So I'm trying to invoke a pointer to a function, but I'm failing. Could

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.