我無法實現正確的方式來使用C++/CLI中使用CSharp實現此原型。從C#調用C++/CLI公共參考類的靜態成員
C++/CLI實現:
// MyClassLib.h
#pragma once
using namespace System;
namespace MyClassLib
{
public ref class MyClass
{
public:
int Increment(int number);
static int SIncrement(int number);
};
}
// This is the main DLL file.
#include "stdafx.h"
#include "MyClassLib.h"
namespace MyClassLib
{
int MyClass::Increment(int number)
{
return number+1;
}
int MyClass::SIncrement(int number)
{
return number+1;
}
}
用法實現:
using System;
using System.Runtime.InteropServices;
using MyClassLib;
namespace UseClassLib
{
class Program
{
[DllImport("MyClassLib.dll")]
public static extern int SIncrement(int number);
static void Main(string[] args)
{
MyClass mc = new MyClass();
int number = 1;
number = mc.Increment(number); // increment ok
number = SIncrement(number); // System.EntryPointNotFoundException here
}
}
}