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

  • Home
  • SEARCH
  • 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 8457487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:49:15+00:00 2026-06-10T12:49:15+00:00

I’m working on my first C++/CLI wrapper and am getting very confused wrt pointers.

  • 0

I’m working on my first C++/CLI wrapper and am getting very confused wrt pointers. In the particular project I’ve got, I’m attempting to wrap an unmanaged C++ dll so I can use it in a C# app. Two objectives here: (1) to be able to use the library in my app, and (2) to learn to do this. Many hours of searching on this site and Google have yielded a bunch of answers that come close; I just can’t seem to get all the way there. The unmanaged library I’m trying to incorporate is the key-value store “LevelDB” (I know of at least one .NET wrapper out there but, like I said, I’m trying to learn this).

The code below is the beginning of a CLI wrapper class written as if in unmanaged code. I.e. this, functionally, is what I’m trying to accomplish. Not surprisingly, this generates the following compiler error:

cannot convert parameter 3 from 'cli::interior_ptr<Type>' to 'leveldb::DB **'

When I began, I naively thought that I could/should replace the DB* pointer with a pinned pointer, something like

pin_ptr<leveldb::DB*> db

but this yields a similar error and doesn’t work. Other combinations with interior pointers and handles (which, if I understand right, are not applicable here because the library is unmanaged) haven’t worked either. I’d appreciate any advice pointing me in the right direction. Any references to good posts/articles would be great too but please include a word or two on how to adapt for my case since, after reading tons of them, I seem to be no closer. Thanks!

Example wrapping class:

#pragma once
#include "leveldb/db.h"

using namespace System;

namespace Wrapper
{
    public ref class DBWrapper 
    {
        leveldb::DB* db;

    public:
        DBWrapper()
        {
            leveldb::Options options;
            options.create_if_missing = true;
            leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db);
        }

        ~DBWrapper() 
        {
            delete db;
        }
    };
}
  • 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-10T12:49:16+00:00Added an answer on June 10, 2026 at 12:49 pm

    Use a local variable:

    DBWrapper()
    {
        leveldb::Options options;
        options.create_if_missing = true;
    
        leveldb::DB* local_db(nullptr);
        leveldb::Status status =leveldb::DB::Open(options, "/tmp/testdb", &local_db);
        db = local_db;
    }
    

    The object under construction (pointed to by this) can be moved by the garbage collector, so a member variable does not have a fixed address.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
i got an object with contents of html markup in it, for example: string
I'm making a simple page using Google Maps API 3. My first. One marker
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.