Skip to content

Commit 002c005

Browse files
save file
1 parent ff22c4a commit 002c005

1 file changed

Lines changed: 108 additions & 17 deletions

File tree

blog/26-04-16/node-gyp-always-on-top/node-gyp-always-on-top.html

Lines changed: 108 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,25 @@
4343
<script>
4444
console.log('node-gyp-always-on-top.html');
4545

46-
46+
var project;
47+
4748
async function ready(){
4849
debug('ready');
49-
50+
project = mod['project'];
51+
5052
initdom(document.body);
5153

54+
55+
var data = {
56+
'always-on-top.cpp' : null,
57+
'always-on-top.js' : null,
58+
'binding.gyp' : null,
59+
'node_modules' : {},
60+
};
61+
62+
var ndata = project.build(data);
63+
project.display(ndata,{});
64+
5265
}//init
5366

5467

@@ -93,41 +106,41 @@ <h1 slot=title>
93106
</div>
94107

95108
<p>
96-
In this example we will create a tool to be able to keep a window on top. First the source code we will be using.
109+
In this example we will create a tool to be able to keep a window on top.
97110
</p>
98111

99112
</div>
100113

101114

102-
103-
<web-editor component id=cpp src='ex/always-on-top.cpp' fullsize></web-editor>
104-
105-
<web-editor component id=js src='ex/always-on-top.js' fullsize></web-editor>
106-
107-
<web-editor component id=gyp src='ex/binding.gyp' fullsize></web-editor>
108-
109-
110-
111115
<div class=blog-text>
112116

113117
<div class=blog-hdr>
114-
node-addon-api
118+
Environment
115119
</div>
116120

117121
<p>
118122

119-
Windows environment
120-
Windows 10 or 11
121-
123+
Windows environment ( Windows 10 or 11 )
124+
<br>
122125
Node.js installed (version you used)
126+
<br>
123127

124128
Python installed (3.8–3.12)
125129

130+
<br>
131+
<br>
132+
133+
we'll set the following up in the course of this blog
134+
<br>
135+
126136
Visual Studio Build Tools installed
137+
<br>
127138

128139
MSVC v14.x
140+
<br>
129141

130142
Windows 10/11 SDK
143+
<br>
131144

132145
MSBuild
133146

@@ -136,6 +149,48 @@ <h1 slot=title>
136149
</div>
137150

138151

152+
<div class=blog-text>
153+
154+
<div class=blog-hdr>
155+
Directory Structure
156+
</div>
157+
158+
<p>
159+
160+
The project will be using the following directory structure
161+
162+
</p>
163+
164+
</div>
165+
166+
<dir-tree component id=project></dir-tree>
167+
168+
169+
<div class=blog-text>
170+
171+
<div class=blog-hdr>
172+
Source Code
173+
</div>
174+
175+
<p>
176+
177+
Will be using the following source code
178+
179+
</p>
180+
181+
</div>
182+
183+
184+
<web-editor component id=cpp src='ex/always-on-top.cpp' fullsize></web-editor>
185+
186+
187+
<web-editor component id=js src='ex/always-on-top.js' fullsize></web-editor>
188+
189+
190+
<web-editor component id=gyp src='ex/binding.gyp' fullsize></web-editor>
191+
192+
193+
139194
<div class=blog-text>
140195

141196
<div class=blog-hdr>
@@ -144,21 +199,30 @@ <h1 slot=title>
144199

145200
<p>
146201
node-addon-api is not a library in the usual sense.
202+
<br>
147203
It’s not a DLL, not a binary, not something you “run”.
148204

205+
<br>
149206
It’s a header‑only C++ wrapper around Node’s native C API (N‑API).
207+
<br>
150208

151209
Meaning:
210+
<br>
152211

153212
It gives you C++ classes instead of raw C functions
213+
<br>
154214

155215
It makes writing addons much easier
216+
<br>
156217

157218
It handles memory safety, exceptions, type conversions
219+
<br>
158220

159221
It hides the ugly parts of N‑API
222+
<br>
160223

161224
It compiles into your addon — nothing is loaded at runtime
225+
<br>
162226

163227
It’s basically a helper layer that makes writing C++ addons sane.
164228
</p>
@@ -171,25 +235,35 @@ <h1 slot=title>
171235

172236
<p>
173237
Inside node-addon-api, you’ll find:
238+
<br>
174239

175240
napi.h
241+
<br>
176242

177243
napi-inl.h
244+
<br>
178245

179246
C++ classes like Napi::Env, Napi::Object, Napi::Function
247+
<br>
180248

181249
Templates for converting JS ↔ C++ types
250+
<br>
182251

183252
Exception wrappers
253+
<br>
184254

185255
ThreadSafeFunction helpers
256+
<br>
186257

187258
Async worker helpers
259+
<br>
188260

189261
There is no compiled code.
262+
<br>
190263
It’s all headers.
264+
<br>
191265

192-
Your addon compiles these headers into your .node binary.
266+
The addon compiles these headers into your .node binary.
193267
</p>
194268

195269
<p>
@@ -214,30 +288,47 @@ <h1 slot=title>
214288

215289
<p>
216290
When installing Visual Studio Build Tools, you only need:
291+
<br>
217292

218293
MSVC v14.x C++ Build Tools
294+
<br>
219295
This gives you:
296+
<br>
220297

221298
cl.exe (the compiler)
299+
<br>
222300

223301
link.exe (the linker)
302+
<br>
224303

225304
Standard C++ headers
226305

306+
<br>
307+
<br>
308+
227309
Windows 10/11 SDK (any version)
310+
<br>
228311
This gives you:
312+
<br>
229313

230314
user32.lib (for RegisterHotKey, SetWindowPos, etc.)
315+
<br>
231316

232317
kernel32.lib
318+
<br>
233319

234320
windows.h
321+
<br>
322+
<br>
235323

236324
Win32 API headers
325+
<br>
237326

238327
MSBuild Tools
328+
<br>
239329

240330
Used internally by node‑gyp to orchestrate the build.
331+
<br>
241332

242333
That’s it.
243334
</p>

0 commit comments

Comments
 (0)