0

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!

  • Could you please post the full error at compile time or running time? – Jiwan May 05 '13 at 12:26
  • An unhandled exception of type 'System.EntryPointNotFoundException' occurred in GeneratorCsharp.exe Additional information: Unable to find an entry point named 'Vytvor_Triedu' in DLL 'DllTriedaGenerator.dll'. – user2351803 May 05 '13 at 13:41

1 Answers1

0

Well, you should use dumpbin, find the mangled name of your function then add EntryPoint="yourMangledName" in your DllImport attribute.

Jiwan
  • 731
  • 4
  • 11