Environment configuration:
Compilation environment: VS2019
Create two projects:
Set Sandbox as startup item:
Set the configuration properties of the sandbox - General - Output Directory\Intermediate Directory as follows:
Preprocessing definition: In order to configure some functions that can only be used by Windows.
Set the configuration properties of YOTOEngin (my own name) - General - Output Directory\Intermediate Directory as follows: Change the configuration type to dll.
Preprocessing definition: In order to configure some functions that can only be used by windows, and distinguish in core.h whether the dll is exported or imported in this package.
Additional include directories: used to include #include<YOTO.h>
Create files in the following format: bin and bin-int are automatically generated files:
Architecture understanding: (personal understanding)
Sandbox and YOTOEngine are separated, that is, the engine functions are written separately in YOTOEngine, and Sandbox is just the startup and configurator (client) of the function. I still don’t know why it’s designed like this, it’s just a guess, the author is too bad.
Code part:
YOTOEngine:
core.h: used for dll configuration
Core: Because __declspec(dllexport) is only supported in window, and dll import and export are different under different packages. Why is import not used below? I checked this and found that import is not required except for static classes.
( Understanding of __declspec(dllimport)-CSDN Blog )
#pragma once
//用于dll的宏
#ifdef YT_PLATFORM_WINDOWS
#ifdef YT_BUILD_DLL
#define YOTO_API __declspec(dllexport)
#else
#define YOTO_API __declspec(dllimport)
#endif // DEBUG
#else
#error YOTO_ONLY_SUPPORT_WINDOWS
#endif // YOTO_PLATFORM_WINDOWS
Application.h: Defines a Run function, which starts the program. It needs an entry point and inherits this class.
#pragma once
#include"Core.h"
namespace YOTO {
class YOTO_API Application
{
public:
Application();
virtual ~Application();
void Run();
};
//在客户端定义
Application* CreateApplication();
}
Application.cpp
#include "Application.h"
namespace YOTO {
Application::Application() {
}
Application::~Application() {
}
void Application::Run() {
while (true)
{
}
}
}
EntryPoint.h: entry point, main function, this function is to separate the client and the engine
#pragma once
#ifdef YT_PLATFORM_WINDOWS
#include "Application.h"
extern YOTO::Application* YOTO::CreateApplication();
void main(int argc,char** argv) {
auto app = YOTO::CreateApplication();
app->Run();
delete app;
}
#endif
YOTO.h
#pragma once
#include "YOTO/Application.h"
//入口点
#include"YOTO/EntryPoint.h"
Sandbox:
SandboxApp.cpp: Client class, only needs to inherit and complete the CreateApplication method
#include<YOTO.h>
class Sandbox:public YOTO::Application
{
public:
Sandbox() {
}
~Sandbox() {
}
private:
};
YOTO::Application*YOTO::CreateApplication() {
return new Sandbox();
}
Before running, please generate YOTOEngine first, and then drag bin\Debug-x64\YOTOEngine\YOTOEngine.dll into the bin\Debug-x64\SandBox folder
test:
Add a printf("helloworld") before new;
operation result:
Updated from time to time