そのため、/clr フラグを使用して、開発中のプロジェクトを .lib にコンパイルすることに成功しました。私が今苦労しているのは、CLR クラス ライブラリ ラッパーを作成して、.NET で使用できるようにすることです。
CLR クラス ライブラリをコンパイルしようとすると、次のエラーが発生します。
Renderer.obj : error LNK2028: unresolved token (0A000017) "public: __thiscall cMain::cMain(void)" (??0cMain@@$$FQAE@XZ) referenced in function "private: void __clrcall Renderer::GraphicsBox::NewGraphicsBox(int,int,int,int)" (?NewGraphicsBox@GraphicsBox@Renderer@@$$FA$AAMXHHHH@Z)
Renderer.obj : error LNK2019: unresolved external symbol "public: __thiscall cMain::cMain(void)" (??0cMain@@$$FQAE@XZ) referenced in function "private: void __clrcall Renderer::GraphicsBox::NewGraphicsBox(int,int,int,int)" (?NewGraphicsBox@GraphicsBox@Renderer@@$$FA$AAMXHHHH@Z)
関連するエントリを include ディレクトリに追加し、関連するエントリを lib ディレクトリに追加しました。
コードは次のようになります。
stdafx.h
#pragma once
#include "cMain.h"
Renderer.h
#pragma once
#include "Stdafx.h"
using namespace System;
namespace Renderer {
public ref class GraphicsBox
{
GraphicsBox();
~GraphicsBox();
void NewGraphicsBox(System::Int32 scrw, System::Int32 scrh, System::Int32 posx, System::Int32 posy);
// TODO: Add your methods for this class here.
};
}
Renderer.cpp
#include "stdafx.h"
#include "Renderer.h"
pragma comment(lib "DX11test.lib")
using namespace Renderer;
GraphicsBox::GraphicsBox()
{
}
GraphicsBox::~GraphicsBox()
{
}
void GraphicsBox::NewGraphicsBox(System::Int32 scrw, System::Int32 scrh, System::Int32 posx, System::Int32 posy)
{
cMain *base;
bool result;
base = new cMain;
if (!base)
{
throw runtime_error("Failed at base = cMain");
}
}
そして、私が参照しようとしているクラス:
cMain.h
#ifndef _CMAIN_H_
#define _CMAIN_H_
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <vector>
#include <map>
#include <string>
#include "InputHandler.h"
#include "cGraphics.h"
#include "cVehicleObject.h"
#include "cVehicleModel.h"
#include "cTerrainModel.h"
#include "cLight.h"
using namespace std;
public class cMain
{
public:
cMain();
cMain(const cMain& other);
~cMain();
bool Initialize(int scrWidth, int scrHeight);
void Shutdown();
void Run();
LRESULT CALLBACK MessageHandler(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam);
private:
bool Frame();
void InitializeWindows(int& scrw, int& scrh);
void CreateNewWindow(int& scrw, int& scrh, int posx, int posy);
void ShutdownWindows();
void ErrorDump(vector<string> errors, string filename);
void ErrorDump(string error, string filename);
bool SetUpLights();
bool SetUpObjects();
LPCWSTR m_applicationName;
HINSTANCE m_hinstance;
HWND m_hwnd;
InputHandler* m_input;
cGraphics* m_graphics;
cObject::GameObjects m_gameObjects;
vector<cLight> m_lights;
};
static LRESULT CALLBACK WndProc(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam);
static cMain* ApplicationHandle = 0;
#endif
ライブラリとしてセットアップしようとしているプロジェクト内での Windows API の使用に関係があると直感的に言えますが、物事をリンクするのに慣れていないので、正直わかりません。
全体を完全に CLR フレンドリーに変換したいと考えています。助けてくれてありがとう