c# - System.EntryPointNotFoundException 即使在 c# 代码中指定入口点(函数名)之后
问题描述
浏览了许多文章和堆栈溢出链接,但找不到解决方案,或者可能犯了一些愚蠢的错误。因此,如果有人可以帮助我解决问题,请在此处发布我的代码。非常感激。提前致谢。
外部文件
#define EXPORT extern "C" __declspec( dllexport ) __cdecl FillAndReturnString(char **someString);
#include <string.h>
#include <stdlib.h>
static void _stdcall FillAndReturnString(char **someString)
{
*someString = (char*)malloc(sizeof(200));
strcpy_s(*someString, 200, "This is a sample Test");
}
程序.cs
using System;
using System.Runtime.InteropServices;
namespace CallingCpp
{
class Program
{
static void Main(string[] args)
{
IntPtr ptr = IntPtr.Zero;
NativeTest.FillAndReturnString(ref ptr);
String s = Marshal.PtrToStringAnsi(ptr);
Console.WriteLine(s);
Console.ReadKey();
}
}
public static class NativeTest
{
private const string DllFilePath = @"C:\Test\MemoryTest\MemoryTestApp.dll";
[DllImport(DllFilePath, EntryPoint = "FillAndReturnString")]
public static extern void FillAndReturnString(ref IntPtr ptr);
}
}
一些我尝试过但没有成功的设置:
从 cpp 项目属性启用 CLR 支持。错误:严重性代码描述项目文件行抑制状态错误 D8016“/clr”和“/EHs”命令行选项不兼容 MemoryTestApp [项目路径]
将 CPP 项目属性中的调用约定设置为 __cdecl(/Gd)。我也尝试使用 __stdcall 在文件中指定。
[DllImport(DllFilePath, EntryPoint = "FillAndReturnString", CallingConvention = CallingConvention.StdCall)] public static extern void FillAndReturnString(ref IntPtr ptr);
使用 Dependency Walker 检查了 cpp dll,但它引发了错误:未找到至少一个必需的隐式或转发的依赖项。
解决方案
推荐阅读
- xcode - 当我调用 swiftUI 视图时,Xcode SwiftUI 与 ViewController 混合,导航栏出现带有后退按钮,单击后如何将其删除
- ffmpeg - FFmpeg - 捕获一个 rtsp 流并将其重新流式传输到另一个 rtsp-server
- .net - HttpListener 认证
- css - CSS仅更改表格中没有i列的一行的属性
- delphi - 将字符串填充到固定列宽
- laravel - 如何将参数传递给模拟类构造函数
- opencv - 如何将 System.drawing.pointF 转换为 OpenCvSharp.Point
- javascript - 显示 Map 中的数组元素
- java - 未找到用于签名配置“发布”颤振的密钥库文件
- bash - Bash如何从参数解析关联数组?