【问题标题】:Unable to find an entry point named '<function>' in DLL '<DLL_name>'在 DLL '<DLL_name>' 中找不到名为 '<function>' 的入口点
【发布时间】:2013-02-28 20:24:11
【问题描述】:

我想从 C# 中调用方法“Talk”。我浏览了其他相关帖子,但对我没有帮助。

Managed.Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Runtime.InteropServices;

namespace Managed
{
    class Program
    {
        [DllImport("Unmanaged.exe", CallingConvention=CallingConvention.Cdecl,EntryPoint="Talk",CharSet=CharSet.Ansi)]
        public static extern int Talk();
        static void Main(string[] args)
        {
            int value=Talk();
        }
    }
}

非托管.h

#ifndef UNMANAGED_H
#define UNMANAGED_H
extern "C"
{
__declspec(dllexport) int Talk();
}
#endif

非托管.cpp

#include "stdafx.h"
#include "conio.h"
#include "Unmanaged.h"

int Talk()
{
    int x=10,y=5;
    return (x+y);
}

【问题讨论】:

  • 您是否已将非托管 DLL 复制到与 C# 可执行文件相同的文件夹中? Edit 等等,你是在调用 EXE 吗?你不应该那样做。您需要创建一个 DLL。
  • 转到您的客户端应用程序-->添加-->现有项目--> 找到生成 dll 的路径-->选择 DLL --> 添加为链接完成了

标签: c# interop pinvoke


【解决方案1】:

您需要将库部署为DLLDllImport 仅适用于使用 P/Ivoke 的 .dll 库。

在 VS 中创建 DLL 时,选择 Win32 下的 Console Application 并将单选按钮设置为“Dynamic-Link-Library (DLL)”。

然后照你做的。有关一些信息,请参阅here

【讨论】:

    猜你喜欢
    • 2017-02-18
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2012-07-06
    • 2012-12-08
    • 2021-08-05
    • 2017-08-31
    相关资源
    最近更新 更多