-1

I know there are many other questions like this, but no one has helped me out. So I'm writing a dll for my mysql connection in c++ to use it later in C#. But it says to me that it can't find the entrypoint of my method.

Any ideas?

Here is my C++ code:

Sweepape.h

#ifdef SWEEPAPE_EXPORTS
#define SWEEPAPE_API __declspec(dllexport)
#else
#define SWEEPAPE_API __declspec(dllimport)
#endif

extern "C" {

    //// Diese Klasse wird aus der DLL exportiert.
    //class SWEEPAPE_API CSweepape {
    //public:
    //  CSweepape(void);
    //  // TODO: Methoden hier hinzufügen.
    //};
    //
    //extern SWEEPAPE_API int nSweepape;
    //extern SWEEPAPE_API int nYear;
    //
    //SWEEPAPE_API int fnSweepape(void);
    
    SWEEPAPE_API int connect2(int a);
    
}

Sweepape.cpp

#include "Sweepape.h"

SWEEPAPE_API int connect2(int a)
{
    std::cout << "Connecting" << a;
    return 0;
}

C#

using System;
using System.Runtime.InteropServices;

namespace ConsoleApp1
{
    class Program
    {
        private const string path = @"C:\Users\chris\source\repos\Sweepape\Debug\Sweepape.dll";


        [DllImport(path, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
        public static extern int connect2(int a);

        static void Main(string[] args)
        {
            connect2(2);

        }
    }
}
chrischtel
  • 11
  • 2
  • 6

1 Answers1

1

You're not really giving us much to work with here, so the most likely causes probably are:

  1. Your C++ library is 32-bit and your C# application is 64-bit, since those are the defaults. You need both to be the same "bitness".

  2. That hard coded path is a screaming red flag. Set up your environment properly, nobody is going to use your code like that. Including you, as you can plainly see.

  3. Depending on your compiler and settings, you're lying about your calling convention. Since you don't explicitly write your calling convention in your C++ code and don't show anything of use (like how you actually compile that code), it's hard to say.

  4. Less likely to be a problem here, but you absolutely are lying about your C++ charset. There's no unicode code in there.

Blindy
  • 65,249
  • 10
  • 91
  • 131