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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:50:15+00:00 2026-06-15T14:50:15+00:00

I have 2 native c++ dlls, say A and B. Class X lives in

  • 0

I have 2 native c++ dlls, say A and B. Class X lives in A.dll, and class Y lives in B.dll, with an interface that requires a shared_ptr<X>. I’d like to instantiate X and hand it over to Y using this interface, within a C# app.

Because these two types live in different dlls, I build them separately using swig -dllimport A -c++ -csharp A.i, and swig -dllimport B -c++ -csharp B.i. Within A.i, I’ve used the %shared_ptr(X) macro allowing me to use an object of type X fluidly in all interfaces that require shared_ptr<X> (provided those interfaces are in A.dll).

My problem is, what if class Y in B.dll takes a shared_ptr<X> in it’s interface? How can I make that second swig build, with B.i, aware of shared_ptr<X> (which lives in A.dll)?

  • 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-15T14:50:17+00:00Added an answer on June 15, 2026 at 2:50 pm

    What you’re looking for is %import in SWIG. You can use this as follows, for example with a module test1:

    %module test1
    
    %include <std_shared_ptr.i>
    
    %shared_ptr(Foo);
    
    %inline %{
      struct Foo {};
      std::shared_ptr<Foo> foo() {
        return std::make_shared<Foo>();
      }
    %}
    

    Which can be referenced from another module, test2:

    %module test2
    
    %import "test1.i"
    
    %inline %{
      void bar(std::shared_ptr<Foo>) {
      }
    %}
    

    What %import does (in an nutshell) is to read the interface, but not generate any wrapper code for it. That is to say it will be aware of the contents of it but not directly output any thing into the wrapper because of it.

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

Sidebar

Related Questions

I have a JAR library that needs a native DLL library to work properly
Title explains. I have native C++ dlls that I'm writing C++/CLI wrappers for, which
I have a native object (C++) that has a gcroot pointer to a managed
I have a native DLL which outputs via stdout / stderr. I have a
I have a native C++ DLL, and I want to import a C# DLL
I have a native/unmanaged DLL and it has a CreateObject function which returns a
This is probably a multi-part question. Background: we have a native (c++) library that
I have a Visual Studio 2008 project with some legacy native C++ DLL projects,
To add native dll reference I have to add it to project as content
I have a C++ DLL (no code) that I want to expose to .NET

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.