我想从 C# 调用方法“Talk”。我浏览了其他相关帖子,但对我没有帮助。
托管程序.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);
}