メソッド「Talk」をC#から呼び出したい。他の関連する投稿を調べましたが、役に立ちませんでした。
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);
}