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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:45:52+00:00 2026-05-10T20:45:52+00:00

I have a dll that was written in c++, I need to use this

  • 0

I have a dll that was written in c++, I need to use this dll in my c# code. After searching I found that using P/Invoke would give me access to the function I need, but these functions are defined with in a class and use non-static private member variables. So I need to be able to create an instance of this class to properly use the functions. How can I gain access to this class so that I can create an instance? I have been unable to find a way to do this.

I guess I should note that the c++ dll is not my code.

  • 1 1 Answer
  • 4 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. 2026-05-10T20:45:53+00:00Added an answer on May 10, 2026 at 8:45 pm

    There is no way to directly use a C++ class in C# code. You can use PInvoke in an indirect fashion to access your type.

    The basic pattern is that for every member function in class Foo, create an associated non-member function which calls into the member function.

    class Foo { public:   int Bar(); }; extern 'C' Foo* Foo_Create() { return new Foo(); } extern 'C' int Foo_Bar(Foo* pFoo) { return pFoo->Bar(); } extern 'C' void Foo_Delete(Foo* pFoo) { delete pFoo; } 

    Now it’s a matter of PInvoking these methods into your C# code

    [DllImport('Foo.dll')] public static extern IntPtr Foo_Create();  [DllImport('Foo.dll')] public static extern int Foo_Bar(IntPtr value);  [DllImport('Foo.dll')] public static extern void Foo_Delete(IntPtr value); 

    The downside is you’ll have an awkward IntPtr to pass around but it’s a somewhat simple matter to create a C# wrapper class around this pointer to create a more usable model.

    Even if you don’t own this code, you can create another DLL which wraps the original DLL and provides a small PInvoke layer.

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

Sidebar

Related Questions

I have a test suite DLL written in C# that uses Selenium.This is then
I have a C++/CLI DLL that uses some managed code (written in C#). I
I have a DLL that is written in C++ and I want to suppress
I have an MFC extension DLL that I've written. It contains derived classes of
I have written a c# program that calls a c++ dll that echoes the
I have a DLL, written in XE2 that takes a PChar as a parameter
I have an application written in PHP that uses a COM dll written in
I have a very simple DLL written in unmanaged C++ that I access from
I have a program written in VB.Net (Visual Studio 2008) that uses a DLL
I have a third-party (Win32) DLL, written in C, that exposes the following interface:

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.