简体   繁体   中英

Missing entry point in my C#/C++ interoperability

I work on my program, which I need for my bachelor work(C#/C++ interoperability) and I have problem with missing entry point in my code... I try create simply number generator, which will be genarated number in C++ class calling from C# ... At first I don't know how I pass a class, but then I found way how to do it on this page... Please help me fix it...

I added my code:

[C++]

#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;


__declspec(dllexport) class Generator
    {
private:
    int zaciatok;
    int koniec;
    int pocetprvkov;
    int *pole;
public: 
      Generator(){}


      void Vytvor (int zaciatok, int koniec, int pocetprvkov)
    {
         srand((unsigned)time(0));
         pole= new int [pocetprvkov]; 
    }

       void Napln()
    {
        for(int a=0; a<pocetprvkov; a++)
          {
              pole[a] = rand() % (koniec - zaciatok +1) + zaciatok;
         }
    }
       void Vypis()
    {
        for(int a=0; a<pocetprvkov; a++)
        cout << pole[a] << endl;
    }

      ~Generator()
       {
           delete[] pole;
           pole= 0;
       }

    };

extern "C" 
{
 __declspec(dllexport) Generator* Vytvor_Triedu() { return new Generator(); }
 __declspec(dllexport) void Vytvor(Generator* prva) {prva->Vytvor(5,25,4); }
 __declspec(dllexport) void Napln(Generator* prva) {prva->Napln(); }
 __declspec(dllexport) void Vypis(Generator* prva) {prva->Vypis(); }
 __declspec(dllexport) void Vymaz(Generator* prva) { delete prva; }
} 

[C#]

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

namespace GeneratorCsharp
{
    class Program
    {
        [DllImport("DllTriedaGenerator.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr Vytvor_Triedu();

        [DllImport("DllTriedaGenerator.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void Vytvor(IntPtr value);

        [DllImport("DllTriedaGenerator.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void Napln(IntPtr value);

        [DllImport("DllTriedaGenerator.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void Vypis(IntPtr value);

        [DllImport("DllTriedaGenerator.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void Vymaz(IntPtr value);

        static void Main(string[] args)
        {
            IntPtr trieda = Vytvor_Triedu();
            Vytvor(trieda);
            Napln(trieda);
            Vypis(trieda);
            Vymaz(trieda);


        }
    };
}

Thanks a lot!

好吧,您应该使用dumpbin,找到函数的乱码,然后在DllImport属性中添加EntryPoint =“ yourMangledName”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM