缺少c# / c++互操作性的入口点
Missing entry point in my C#/C++ interoperability
我在我的程序上工作,我需要我的学士工作(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);
}
};
}
非常感谢!
那么,您应该使用dumpbin,找到您的函数的名称,然后在您的DllImport属性中添加EntryPoint="yourMangledName"
相关文章:
- COM 互操作性需要强命名程序集吗?
- CComPtr 和 std::shared_ptr 互操作性
- C和C++原子之间的互操作性
- C/C++ 与 C# 的互操作性命名约定
- C和C++中类型的互操作性
- C++与Fortran的互操作性
- 关于C#与非托管C++的互操作性的持续传奇
- java和c++的互操作性
- 如何从C++和通过COM互操作性访问.NET类的属性
- OpenCL/OpenGL 互操作性纹理段错误
- Swift和Objective-C++互操作性
- Windows XP和Windows 7之间的DCOM互操作性
- 寻找C++到 WPF/Cocoa 互操作性的跨平台、端到端示例
- QML 和 C++ 映像互操作性
- GNU Fortran与C的互操作性
- linux时区互操作性
- VS 2012与VS 2010的互操作性
- 互操作性的工作原理
- C++到D的互操作性
- 缺少c# / c++互操作性的入口点