123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- #pragma once
- // 下列 ifdef 块是创建使从 DLL 导出更简单的
- // 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 CCOSCONSOLESCRIPT_EXPORTS
- // 符号编译的。在使用此 DLL 的
- // 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将
- // CCOSCONSOLESCRIPT_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的
- // 符号视为是被导出的。
- #ifndef CCOSCONSOLESCRIPT_EXPORTS
- #ifdef _WIN64
- #ifdef _DEBUG
- #define DCSBASE "CcosConsoleScriptX64D"
- #pragma comment(lib, "CcosConsoleScriptX64D.lib")
- #else
- #define DCSBASE "CcosConsoleScriptX64"
- #pragma comment(lib, "CcosConsoleScriptX64.lib")
- #endif
- #else
- #ifdef _DEBUG
- #define DCSBASE "CcosConsoleScriptD"
- #pragma comment(lib, "CcosConsoleScriptD.lib")
- #else
- #define DCSBASE "CcosConsoleScript"
- #pragma comment(lib, "CcosConsoleScript.lib")
- #endif
- #endif
- #endif
- #ifdef CCOSCONSOLESCRIPT_EXPORTS
- #define CCOSCONSOLESCRIPT_API __declspec(dllexport)
- #define CCOSCONSOLESCRIPT_CAPI extern "C" __declspec(dllexport)
- #else
- #define CCOSCONSOLESCRIPT_API __declspec(dllimport)
- #define CCOSCONSOLESCRIPT_CAPI extern "C" __declspec(dllimport)
- #endif
- typedef enum _DCS_RET {
- DCS_NOT_SUPPORT = -1,
- DCS_FAILED = 0,
- DCS_SUCCEED = 1,
- DCS_MAX
- }DCS_RET;
- #include <map>
- #include <string>
- #include "ResDataObject.h"
- #pragma warning( push )
- #pragma warning( disable : 4311 )
- #pragma warning( disable : 4312 )
- #pragma warning( disable : 4302 )
- template <class T1>
- DCS_RET TempRunClassFunc(T1 *p, ResDataObject &Req)
- {
- DCS_RET ret = DCS_NOT_SUPPORT;
- typedef DCS_RET (T1::*classMember) (ResDataObject &Req);
- typedef union _funcContext {
- classMember func;
- UINT32 Addr32;
- UINT64 Addr64;
- }FUNCCONTEXT;
- FUNCCONTEXT fc;
- memset(&fc, 0, sizeof(fc));
- const char *pFunc = p->GetFunc((const char*)Req[0]);
- if (pFunc)
- {
- if (sizeof(char*) == 4)
- {
- //RegistIF((char*)(fc.Addr32));
- fc.Addr32 = (UINT32)pFunc;
- }
- else if (sizeof(char*) == 8)
- {
- //RegistIF((char*)(fc.Addr64));
- fc.Addr64 = (UINT64)pFunc;
- }
- classMember Func = fc.func;
- if (Func)
- {
- return (p->*Func)(Req);
- }
- }
- return ret;
- }
- #define MacroRun(Req) TempRunClassFunc(this,Req)
- template <class T1, class T2>
- bool TempRegistClassFunc(T1 *p, T2 Addr, const char *pCmd)
- {
- typedef DCS_RET (T1::*classMember) (ResDataObject &Req);
- classMember func = (classMember)Addr;
- typedef union _funcContext {
- classMember func;
- UINT32 Addr32;
- UINT64 Addr64;
- }FUNCCONTEXT;
- FUNCCONTEXT fc;
- memset(&fc, 0, sizeof(fc));
- fc.func = func;
- if (sizeof(char*) == 4)
- {
- return p->MakeCmd(pCmd,(char*)(fc.Addr32));
- //RegistIF((char*)(fc.Addr32));
- }
- else if (sizeof(char*) == 8)
- {
- //RegistIF((char*)(fc.Addr64));
- return p->MakeCmd(pCmd, (char*)(fc.Addr64));
- }
- assert(0);
- return false;
- }
- #pragma warning( pop )
- #define MacroRegist(ClassType,Addr) TempRegistClassFunc<ClassType>(this,&ClassType::Addr,#Addr)
- //#define RUNCMD(CLASSTYPE,Req) { \
- // DCS_RET ret = DCS_NOT_SUPPORT; \
- // PVOID Addr = GetCmd((const char *)#Req[0]); \
- // if (Addr) { \
- // typedef DCS_RET(#CLASSTYPE"::"*ClassFunc)(ResDataObject &Req); \
- // ClassFunc Func = (ClassFunc)Addr; \
- // ret = ((*this).*ClassFunc)(Req); \
- // } \
- // return ret; \
- //} \
- // 此类是从 CcosConsoleScript.dll 导出的
- class CCOSCONSOLESCRIPT_API CcosConsoleScript {
- map<string, const char*> *m_pCommandMap;
- public:
- CcosConsoleScript(void);
- virtual ~CcosConsoleScript();
- bool MakeCmd(const char *pCmd, const char* pClassFunc);
- const char* GetFunc(const char *pCmd);
- virtual void Help();
- //inputcmd : helloworld 2020 Joy_Derk
- //[0]:helloworld
- //[1]:2020
- //[2]:Joy_Derk
- //[0]:command,[1]:P1,[2]:P2...
- static ResDataObject SeperateCommand(const char *pReq);
- virtual DCS_RET Command(ResDataObject &Req);
- };
- //CCOSCONSOLESCRIPT_CAPI CcosConsoleScript* LoadDCS();//user要集成此功能
- typedef CcosConsoleScript* (*LOADDCS)();
- typedef void(*UNLOADDCS)(CcosConsoleScript *p);
|