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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:31:06+00:00 2026-06-05T07:31:06+00:00

I wrote simple C++ Dll ( win32 ) and i change the properties to

  • 0

I wrote simple C++ Dll ( win32 ) and i change the properties to be ‘Common Language Runtime Support (/clr)’ –

I created new Simple winform project ( C# 4.0 ) and i created reference to the C++ project ( the C++ DLL ).

Now i can’t see the C++ dll in the C# project – i cant use it and i dont know why.

  • 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-05T07:31:08+00:00Added an answer on June 5, 2026 at 7:31 am

    If you have, for example, this unmanaged function:

    bool fooFunction(int firstParameter, int secondParameter);
    

    If you want to make it visible to managed code you have to wrap (as first, simple, step) it into a managed class:

    public ref class MyClass abstract sealed
    {
    public:
        static bool Foo(int firstParameter, int secondParameter)
        {
            return fooFunction(firstParameter, secondParameter);
        }
    };
    

    This is a simple exam, if you have to interop with complex type you may need to wrap them all. For example if you have to interop with a function that accepts a string you have to manage this. Usually I use a class like this:

    ref class UnmanagedString sealed
    {
    public:
        UnmanagedString(String^ content) : _content(content)
        { 
            _unicodePtr = _ansiPtr = IntPtr::Zero; 
        }
    
        ~UnmanagedString()
        { 
            Free(); 
        }
    
        operator LPWSTR()
        { 
            if (_content == nullptr)
                return NULL;
    
            Free();
    
            _unicodePtr = Marshal::StringToHGlobalUni(_content);
            return reinterpret_cast<LPWSTR>(_unicodePtr.ToPointer());
        }
    
        operator LPCSTR()
        { 
            if (_content == nullptr)
                return NULL;
    
            Free();
    
            _ansiPtr = Marshal::StringToHGlobalAnsi(_content);
            return reinterpret_cast<LPCSTR>(_ansiPtr.ToPointer());
        }
    
        virtual System::String^ ToString() override
        {
            return _content;
        }
    
        virtual int GetHashCode() override
        {
            return _content->GetHashCode();
        }
    
        virtual bool Equals(Object^ obj) override
        {
            return _content->Equals(obj);
        }
    
    private:
        IntPtr _unicodePtr, _ansiPtr;
        String^ _content;
    
        void Free()
        {
            if (_unicodePtr != IntPtr::Zero)
            {
                Marshal::FreeHGlobal(_unicodePtr);
                _unicodePtr = IntPtr::Zero;
            }
    
            if (_ansiPtr != ntPtr::Zero)
            {
                Marshal::FreeHGlobal(_ansiPtr);
                _ansiPtr = IntPtr::Zero;
            }
        }
    };
    

    Using this class you can call a function like void foo(LPCSTR pszText) with foo(UnamangedString(myManagedString)). More complex are the calls you have to do and more code you have to write to interop between them.

    Note: simply exposing a 1:1 managed interface to unmanaged functions will make your C# code harder to read, I suggest you write a true OO interface to hide underlying implementation.

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

Sidebar

Related Questions

I'm testing a simple DLL, I wrote using C++/CLI, in a CLR console application.
Using Visual Studio 2005, I wrote a simple DLL in C that uses the
I created c++ dll (using mingw) from code I wrote on linux (gcc), but
I wrote simple load testing tool for testing performance of Java modules. One problem
I wrote a simple javascript function to display a progressbar with the help of
I wrote a simple CMS for one of my clients which does specifically what
I wrote a simple Sinatra app that generate an image using rmagick from some
I wrote a simple webpage as follows: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN
I wrote a simple WinAPI application in C++ which embeds the Abode Flash ActiveX
I wrote a simple contact form for a client in Django. However, whenever it

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.