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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:35:17+00:00 2026-05-22T15:35:17+00:00

I do some thin wrapper of some scientific library (http://root.cern.ch) from unmanaged to managed

  • 0

I do some thin wrapper of some scientific library (http://root.cern.ch) from unmanaged to managed world using C++ cli.

Reading of the special file format (which is the main goal) is implemented through:
1) Once a lifetime call of SetBranchAddress(const char name, void* outputVariable) to let it know an address of your variable
2) Than you N time call GetEntry(ulong numberOfRow) wthich fills this void* outputVariable with the appropriate value;

I put this example of usage :

double myValue; //this field will be filled

//We bind myValue to the 'column' called "x" stored in the file"
TTree->SetBranchAddress("x", &myValue); 

// read first "entry" (or "row") of the file
TTree->GetEntry(0); 

// from that moment myValue is filled with value of column "x" of the first row
cout<<"First entry x = "<<myValue<<endl; 

TTree->GetEntry(100); //So myValue is filled with "x" of 101 row
...

So in C++/CLI code the problem is with binding managed elementary types to this void * pointer;

I have tried 3 approaches:

namespace CppLogicLibrary {
public ref class SharpToRoot
{        
       double mEventX;
       double *mEventY;
       IntPtr memEventZ;

       ///Constructor
       SharpToRoot()
       {
          mEventy = new double();
          memEventZ= Marshal::AllocHGlobal(sizeof(double));
       }

       void SetBranchAddresses()
       {
           pin_ptr<double> pinnedEventX = &mEventX;
           mTree->SetBranchAddress("ev_x", pinnedEventX);
           mTree->SetBranchAddress("ev_y", mEventY);
           mTree->SetBranchAddress("ev_z", memEventZ.ToPointer());
           ...
           //now I read some entry to test... just in place
           mTree->GetEntry(100);
           mTree->GetEntry(101);
           double x = mEventX;
           double y = *mEventY
           double z = (double)Marshal::PtrToStructure(memEventZ, Double::typeid);
       }

       ...

All of 3 variants are compiled with no errors, goes with no exceptions… BUT fills its (void *) values with some rubbish value like 5,12331E-305. In unmanaged code all works fine.

What could be the error with such void* to C++/CLI elementary types binding?

  • 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-05-22T15:35:18+00:00Added an answer on May 22, 2026 at 3:35 pm

    The problem was that internally data was presented by floats inside of this library. So, when it was mapped and processed as doubles on the C# side, it gave 5,12331E-305.

    Each of this 3 variats worked. And, from my point of view, using of
    pin_ptr pinnedEventX = &mEventX;
    was improper in this case, because it doesn’t persist between functions execution;

    What I’m not sure, why this “float” situation was handled in native C++. As I wrote before, there wasn’t any problem.

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

Sidebar

Related Questions

I'm looking for some thin layer on top of handling HTTP requests that can
I am attempting to pull some information from my tnsnames file using regex. I
Some API returns me XmlCursor pointing on root of XML Document. I need to
I am doing a thin wrapper over a third-party framework, i am thinking following
In writing some threaded code, I've been using the ReaderWriterLockSlim class to handle synchronized
I have the understanding that using data access routines directly from presentation code is
I'm trying to do some basic queries using the groovy.sql.Sql object, and I'm getting
I am binding a datagrid to some data and using the AutoColumnGeneration. When using
I'm in the process of porting some code from Linux to Mac OS X.
In some versions of IE, there is a thin 2px border surrounding the document

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.