-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind.js
More file actions
42 lines (36 loc) · 1.23 KB
/
find.js
File metadata and controls
42 lines (36 loc) · 1.23 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
// Wraps a call to GetProcAddress(GetModuleHandle(lib), method)
function Find(lib, method, convention) {
// Make sure it is using "new"
if (!(this instanceof Find)) {
return new Find(lib, method);
}
// Save names
this.lib = lib;
this.method = method;
// Stripped name (without .dll and lower case)
this.name = lib;
this.name = this.name.substring(0, this.name.lastIndexOf('.dll')) || this.name;
this.name = this.name.toLowerCase();
// Get address
this.address = cpp_addressOf(lib, method);
// If no convention has been specified or AUTO was used
convention = convention || CallConvention.AUTO;
if (convention == CallConvention.AUTO) {
var size = ptrSize();
if (size == 4) {
// WINAPIs (in 32 bits arch. only) are STDCALL
if (['kernel32', 'user32', 'gdi32'].indexOf(this.name) >= 0) {
convention = CallConvention.STDCALL;
}
else {
// Default to C/C++ standard
convention = CallConvention.CDECLCALL;
}
}
else if (size == 8) {
convention = CallConvention.FASTCALL;
}
}
// Save convention
this.convention = convention;
}