1
我想从C#调用方法“Talk”。我浏览了其他相关帖子,但它没有帮助我。无法在DLL'<DLL_name>'中找到名为'<function>'的入口点
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();
}
}
}
Unmanaged.h
#ifndef UNMANAGED_H
#define UNMANAGED_H
extern "C"
{
__declspec(dllexport) int Talk();
}
#endif
Unmanaged.cpp
#include "stdafx.h"
#include "conio.h"
#include "Unmanaged.h"
int Talk()
{
int x=10,y=5;
return (x+y);
}
您是否将您的非托管DLL复制到与C#可执行文件相同的文件夹中? [编辑]等等,你正在调用EXE?你不应该那样做。您需要创建一个DLL。 – 2013-02-28 12:24:41
转到您的客户端应用程序 - >添加 - >现有项目 - >到达您的DLL生成路径 - >选择DLL - >添加为链接,你就完成了 – 2015-01-20 07:51:58