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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:51:42+00:00 2026-06-04T01:51:42+00:00

So I have a DLL that I made with C++ and I am using

  • 0

So I have a DLL that I made with C++ and I am using it in C#. The problem is that I use a function pointer in C++, so I made a delegate. The hole program works but after it finishes I got a message box stating that the value of ESP was not saved for the function.

My code:
C++ The DLL

typedef void (*FUNCTION_TYPE)(bool);
extern "C"
{
    DLL void prim(int a, FUNCTION_TYPE myF)
    {
        if(a < 2)
        {
            myF(false);
            return;
        }

        for (int i = 2; i < a; i++)
        {
            if (a % i == 0)
            {
                myF(false);
                return;
            }
        }

        myF(true);
    }
};

My C# code (calling the dll):

delegate void SOME_FUNCTION(bool isFine);

        [DllImport("DLLs")]
        private static extern void prim(int n, SOME_FUNCTION afisare);

        static void afisare(bool isFine)
        {
            if (isFine == true)
                Console.WriteLine("Da, e prim");
            else
                Console.WriteLine("Nu, nu e prim");
        }

        static void Main(string[] args)
        {
            SOME_FUNCTION myAfis = afisare;
            prim(17, myAfis);
        }
  • 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-04T01:51:44+00:00Added an answer on June 4, 2026 at 1:51 am

    You have a calling convention mismatch. The C++ function pointer type uses cdecl. The managed code assumes stdcall. Fix it like this:

    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    delegate void SOME_FUNCTION(bool isFine);
    

    Alternatively you could change the calling convention in the C++ code to stdcall:

    typedef void (__stdcall *FUNCTION_TYPE)(bool);
    

    But make sure you do only one of these and not both!

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

Sidebar

Related Questions

Here's my problem: I have an unmanaged dll that I made.I'm calling one of
I have a PyQt4 program that I froze using cx_freeze. The problem I am
I have a DLL that I can use to pull the following information about
I have DLL and application that will call some function in this dll. For
I have a DLL made in C++ that is then used in a C#
I have a common dll that I am using for my project. We have
I have a DLL that is written in C++ and I want to suppress
I have a DLL that's compiled, and I don't have the source code for
I have a .DLL that i include in my Visual Studio 2008 project. The
I have a dll that exports extern C __declspec(dllexport) int __stdcall Foo( void );

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.