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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:52:51+00:00 2026-06-14T16:52:51+00:00

Possible Duplicate: Visual C++ managed app: Unable to find an entry point named ‘Add’

  • 0

Possible Duplicate:
Visual C++ managed app: Unable to find an entry point named ‘Add’

I’m learning to use platform invoke in C#.I follow the tutorial on msdn:

It works perfectly with C++ to use the MathFuncsDll.dll.

When I use:

[DllImport("MathFuncsDll.dll")] 

in my C# code, a dll not found exception raised. Then I change it to:

[DllImport("C:\\...\\MathFuncsDll.dll")] 

then a entry point not found exception appears.

How can I fix these problems?

For clarification, here is my code:
The C++ dll:

header file:

//MathFuncsDll.h

#ifdef MATHFUNCSDLL_EXPORTS
#define MATHFUNCSDLL_API __declspec(dllexport) 
#else
#define MATHFUNCSDLL_API __declspec(dllimport) 
#endif

namespace MathFuncs
{
    class MyMathFuncs
    {
    public:
    // Returns a + b
    static __declspec(dllexport) double Add(double a, double b);

    // Returns a - b
    static __declspec(dllexport) double Subtract(double a, double b);

    // Returns a * b
    static __declspec(dllexport) double Multiply(double a, double b);

    // Returns a / b
    // Throws DivideByZeroException if b is 0
    static __declspec(dllexport) double Divide(double a, double b);
    };
}

The .cpp file:

// MathFuncsDll.cpp
// compile with: /EHsc /LD

#include "MathFuncsDll.h"
#include <stdexcept>

using namespace std;

namespace MathFuncs
{
    double MyMathFuncs::Add(double a, double b)
    {
        return a + b;
    }

    double MyMathFuncs::Subtract(double a, double b)
    {
        return a - b;
    }

    double MyMathFuncs::Multiply(double a, double b)
    {
        return a * b;
    }

    double MyMathFuncs::Divide(double a, double b)
    {
        if (b == 0)
        {
            throw new invalid_argument("b cannot be zero!");
        }
    return a / b;
    }
}

here is the C# app call the functions:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace CSharpConsole
{
    class Program
    {
        //[DllImport("MathDll.dll")]

        [DllImport(@"C:\Users\...\Debug\MathDll.dll")]
        public static extern double Add(double a, double b);
        static void Main(string[] args)
        {
            double a = 6.2;
            int b = 3;

            Console.WriteLine(Add(a,b));
        }
    }
}

I create a completely new solution for this, the first DllIport line still doesn’t work.And the second line give entry point exception.

  • 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-14T16:52:52+00:00Added an answer on June 14, 2026 at 4:52 pm

    When you use

    [DllImport("MathFuncsDll.dll")]
    

    the system will look for the DLL in the DLL search path. The first place searched is the directory which contains your executable file. That’s the best place to put your DLL.

    If you see “entry point not found” then that means simply that the entry point was not found.

    The article you link to does not use p/invoke to link to the C++ DLL. That article describes how to link to a native DLL from managed C++. So you appear to be doing something different from that since you are using C# and p/invoke. Unless you supply precise details of what you are doing, for example the code, it’s hard to prescribe a remedy.


    OK, now you have added some code. That helps a lot.

    You should not use static methods for p/invoke exports. Remove the MyMathFuncs and have plain old C-style functions:

    extern "C" 
    {
    
        double __declspec(dllexport) Add(double a, double b)
        {
             return a + b;
        }
    }
    

    No need for a header file that declares those functions. Just a single .cpp file should get it done. The use of extern "C" stops your names from being mangled by the C++ compiler.

    If you need to inspect your DLL to see what it exports, use Dependency Walker.

    On the C# side use:

    [DllImport(@"...", CallingConvention=CallingConvention.Cdecl)]
    public static extern double Add(double a, double b);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: App.Config Transformation for 'none web projects' in Visual Studio 2010? Basically, the
Possible Duplicate: Use Visual Studio web.config transform for debugging I have an asp.net application
Possible Duplicate: delphi non visual component image How to add my icon to my
Possible Duplicate: How can I use MS Visual Studio for Android Development? Is is
Possible Duplicate: Can I use .NET 4.0 beta in Visual Studio 2008? Hot can
Possible Duplicate: visual c++ 2010 can't add resource file To add bitmap I should
Possible Duplicate: Collection initialization syntax in Visual Basic 2008? How is the following C#
Possible Duplicate: Adding a guideline to the editor in Visual Studio Is there a
Possible Duplicate: Seemingly useless debugging environment for Android I've obviously been spoiled by Visual
Possible Duplicate: Can Visual Studio 2012 be installed side-by-side w/ Visual Studio 2010? Before

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.