【问题标题】:Missing entry point in my C#/C++ interoperability我的 C#/C++ 互操作性中缺少入口点
【发布时间】:2013-05-05 11:56:36
【问题描述】:

我在我的程序上工作,这是我的学士工作(C#/C++ 互操作性)所需要的,并且我的代码中缺少入口点有问题...我尝试创建简单的数字生成器,它将在 C++ 中生成数字从 C# 调用类...起初我不知道如何通过一个类,但后来我在此页面上找到了方法...请帮我解决它...

我添加了我的代码:

[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);


        }
    };
}

非常感谢!

【问题讨论】:

  • 能否请您在编译时或运行时发布完整的错误?
  • GeneratorCsharp.exe 中出现“System.EntryPointNotFoundException”类型的未处理异常附加信息:无法在 DLL“DllTriedaGenerator.dll”中找到名为“Vytvor_Triedu”的入口点。

标签: c# c++ interop entry-point language-interoperability


【解决方案1】:

好吧,你应该使用 dumpbin,找到你的函数的错位名称,然后在你的 DllImport 属性中添加 EntryPoint="yourMangledName"。

【讨论】:

  • 还有其他方法可以找到我的函数的错位名称,因为当我尝试打开 dumpbin 系统错误显示时
  • 我安装了 PE 资源管理器,在那里打开我的 dll,但它只显示入口点的地址,而不是名称......我很绝望
猜你喜欢
  • 1970-01-01
  • 2022-08-15
  • 1970-01-01
  • 2010-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-12
相关资源
最近更新 更多