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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:15:50+00:00 2026-05-25T12:15:50+00:00

I am trying to wrap a C++ library in Objective-C classes for importing into

  • 0

I am trying to wrap a C++ library in Objective-C classes for importing into MonoTouch using btouch. I am trying to get to grips with how to translate the API for use in a managed environment. Specifically, how to handle methods that take in pointers to local variables, like the ULDatabaseManager::OpenConnection static method in the following example:

class UL_CLS_SPEC ULError {
    public:
    ULError();

    /* Gets the error code (SQLCODE) for the last operation. */
    inline an_sql_code GetSQLCode() const {
        return _info.sqlcode;
    }
}

class UL_CLS_SPEC ULDatabaseManager {
    public:
    /* Initializes the UltraLite runtime. */
    static bool Init();

    /* Finalizes the UltraLite runtime. */
    static void Fini();

    /* Opens a new connection to an existing database. */
    static ULConnection * OpenConnection(
        const char * connParms,
        ULError * error = UL_NULL);
}

From Objective-C, this C++ API would be called as follows:

- (void)openConnection {
    if (ULDatabaseManager::Init()) {
        const char * connectionParms;
        ULConnection * conn = nil;
        ULError error;

        connectionParms = [self getConnectionParms];

        // Attempt connection to the database
        conn = ULDatabaseManager::OpenConnection(connectionParms, &error);

        // If database file not found, create it and create the schema
        if (error.GetSQLCode() == SQLE_ULTRALITE_DATABASE_NOT_FOUND) {       
            // Handle error
        }                
    }
}

In this API the caller of the OpenConnection static method is responsible for defining the ULError variable and passing it in as a reference pointer parameter. This paradigm does not seem to translate well into a managed environment, or at least to me it doesn’t seem right to have the caller being responsible for instantiating the ULError object. What would be the best practice for translating this API into Objective-C classes? Which class would be responsible for creating and destroying the ULError object?

I hope that my question makes sense, because I am very new to C++ and Objective-C (and MonoTouch for that matter) so am still at the point where I don’t quite know what I don’t know! 🙂 And feeling a bit out of my depth here at the moment. So I would appreciate any advice or references to good articles that will help explaining how to wrap a C++ API.

PS: I know this question pertains mainly to C++ and Objective-C, but I am including MonoTouch as a tag in case someone what has had experience with using btouch for importing Objective-C classes has some advice to offer.

  • 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-25T12:15:50+00:00Added an answer on May 25, 2026 at 12:15 pm

    The way that I resolved this is to change the API being exposed to Monotouch with btouch. Specifically, methods such as OpenConnection I only required the connectionParms, not the pointer to the error class. I then did error checking in the open method and returned nil if an error occurred. In the wrapper class I also kept a ULError object which I named lastConnectionError and my C++ code passed a pointer to this object with the OpenConnection C++ call. I included a separate method in my wrapper class, GetLastConnectionError, that returned an enum representing the different possible error states.

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

Sidebar

Related Questions

I've been trying to use SWIG to wrap around a simple library that uses
I am trying to wrap a C library using ctypes. One feature of the
I'm trying to wrap a class from a library I'm using in Lua. Specifially,
I am trying to wrap a C++ library (for Sybase Ultralite) with Objective-C so
I'm trying to wrap my head around the enumerator library and ran into a
I am trying to wrap a Java library with a Clojure binding. One particular
Trying to wrap my head around the jQuery .not() function, and running into a
So I'm trying to make use of a GtkSourceView in C++ using GtkSourceViewmm ,
I am trying to create python bindings to a vala library using the following
I'm trying to wrap a c library in a high-level python interface with Boost.Python.

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.