C++の静的ライブラリを、C#から利用する場合を考えます。
C++のクラスを次のように定義し、header.hの名前で保存します。
class Lib
{
public:
int CppFunc();
};
次にC++/CLIで、C++のラッパーを作成します。
public ref class Wrapper
{
public:
int CliFunc();
};
リンカの設定で依存ファイルにC++のライブラリを追加し、それを読み込みます。
#include <header.h>
int Wrapper::CliFunc()
{
Lib* lib = new Lib();
int a = lib->CppFunc();
return a;
}
C#ではC++/CLIのライブラリを、参照の設定から追加します。
class Program
{
static void Main(string[] args)
{
Wrapper wrapper = new Wrapper();
int a = wrapper.CliFunc();
}
}