【发布时间】:2021-08-05 00:50:30
【问题描述】:
我知道还有很多其他类似的问题,但没有人帮助我。 所以我在 C++ 中为我的 mysql 连接编写了一个 dll,以便稍后在 C# 中使用它。但它告诉我它找不到我的方法的入口点。
有什么想法吗?
这是我的 C++ 代码:
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);
}
}
}
【问题讨论】:
-
当您在 C# 中使用 EF.Core 时,为什么还要使用 C++ 中的 MySql?
-
我只是在尝试,c++中还有其他功能。
-
所以您似乎在问为什么您的 C# 代码无法加载您的 c++ DLL,但您没有显示尝试这样做的 C# 代码?
-
对不起,我的错。我忘记了。
-
我添加了 C# 代码。
标签: c# c++ dll entry-point