forked from wamsoft/KAGParserEx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
139 lines (113 loc) · 3.49 KB
/
Main.cpp
File metadata and controls
139 lines (113 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "KAGParserEx.hpp"
#ifndef _WIN32
typedef int32_t HRESULT;
#ifndef EXPORT
#define EXPORT(hr) extern "C" __attribute__((visibility("default"))) hr
#endif
#ifndef S_OK
#define S_OK ((HRESULT)0L)
#endif
#ifndef E_FAIL
#define E_FAIL ((HRESULT)0x80004005L)
#endif
#endif
static iTJSDispatch2 *origKAGParser = NULL;
void kagparserex_init()
{
tTJSNI_KAGParser::initMethod();
iTJSDispatch2 * global = TVPGetScriptDispatch();
if (global) {
tTJSVariant val;
if (TJS_SUCCEEDED(global->PropGet(0, TVP_KAGPARSER_EX_CLASSNAME, NULL, &val, global))) {
origKAGParser = val.AsObject();
val.Clear();
}
iTJSDispatch2 * tjsclass = tTJSNC_KAGParser::CreateNativeClass();
val = tTJSVariant(tjsclass);
tjsclass->Release();
global->PropSet(TJS_MEMBERENSURE, TVP_KAGPARSER_EX_CLASSNAME, NULL, &val, global);
global->Release();
}
}
#ifdef TVP_STATIC_PLUGIN
#define EXPORT(hr) static hr STDCALL
#else
#ifdef _WIN32
#if defined(_MSC_VER)
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __attribute__((visibility("default")))
#endif
#define EXPORT(hr) extern "C" DLL_EXPORT hr STDCALL
#ifdef _MSC_VER
# if defined(_M_AMD64) || defined(_M_X64)
# pragma comment(linker, "/EXPORT:V2Link")
# pragma comment(linker, "/EXPORT:V2Unlink")
# else
# pragma comment(linker, "/EXPORT:V2Link=_V2Link@4")
# pragma comment(linker, "/EXPORT:V2Unlink=_V2Unlink@0")
# endif
#endif
#ifdef __GNUC__
asm (".section .drectve");
# if defined(__x86_64__) || defined(__x86_64)
asm (".ascii \" -export:V2Link=V2Link -export:V2Unlink=V2Unlink\"");
# else
asm (".ascii \" -export:V2Link=V2Link@4 -export:V2Unlink=V2Unlink@0\"");
# endif
#endif
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
#endif
#endif
//---------------------------------------------------------------------------
static tjs_int GlobalRefCountAtInit = 0;
EXPORT(HRESULT) V2Link(iTVPFunctionExporter *exporter)
{
TVPInitImportStub(exporter);
kagparserex_init();
GlobalRefCountAtInit = TVPPluginGlobalRefCount;
return S_OK;
}
//---------------------------------------------------------------------------
EXPORT(HRESULT) V2Unlink()
{
if(TVPPluginGlobalRefCount > GlobalRefCountAtInit) return E_FAIL;
iTJSDispatch2 * global = TVPGetScriptDispatch();
if (global) {
global->DeleteMember(0, TVP_KAGPARSER_EX_CLASSNAME, NULL, global);
if (origKAGParser) {
tTJSVariant val(origKAGParser);
origKAGParser->Release();
origKAGParser = NULL;
global->PropSet(TJS_MEMBERENSURE, TVP_KAGPARSER_EX_CLASSNAME, NULL, &val, global);
}
global->Release();
}
tTJSNI_KAGParser::doneMethod();
TVPUninitImportStub();
return S_OK;
}
#ifdef TVP_STATIC_PLUGIN
#if defined(_MSC_VER)
#define EXPORT_USED __declspec(dllexport)
#else
#define EXPORT_USED __attribute__((visibility("default"), used))
#endif
#define str(x) TJS_W(#x)
#define strx(x) str(x)
#define CAT(a, b) a##b
#define XCAT(a, b) CAT(a, b)
#define MAKE_FUNC(name) XCAT(krkrz_plugin_, name)
// リンク用エントリ関数
// _krkrz_plugin_プロジェクト名 で関数が作られる
extern "C" EXPORT_USED void STDCALL MAKE_FUNC(TVP_PLUGIN_NAME)() {
static iTVPStaticPlugin plugin;
plugin.name = strx(TVP_PLUGIN_NAME);
plugin.link = (int32_t (STDCALL *)(iTVPFunctionExporter *))V2Link;
plugin.unlink = (int32_t (STDCALL *)(void))V2Unlink;
TVPRegisterPlugin(&plugin);
}
#endif