-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathhstring.js
21 lines (17 loc) · 1 KB
/
hstring.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const Struct = require('./struct');
const COM = require('./com');
const Win32 = require('./win32');
var ComBase = {
WindowsCreateString: new NativeFunction(Win32.FindHiddenExport("combase.dll", "WindowsCreateString"), 'uint', ['pointer', 'uint', 'pointer'], Win32.Abi),
WindowsDeleteString: new NativeFunction(Win32.FindHiddenExport("combase.dll", "WindowsDeleteString"), 'uint', ['pointer'], Win32.Abi),
WindowsGetStringRawBuffer: new NativeFunction(Win32.FindHiddenExport("combase.dll", "WindowsGetStringRawBuffer"), 'pointer', ['pointer', 'pointer'], Win32.Abi),
};
module.exports = {
alloc: function (str) {
var ret = new Struct({ 'value': 'pointer' });
COM.ThrowIfFailed(ComBase.WindowsCreateString(Memory.allocUtf16String(str), str.length, ret.Get()));
return ret.value;
},
read: function (hstring) { return Memory.readUtf16String(ComBase.WindowsGetStringRawBuffer(hstring, NULL)); },
free: function (hstring) { return ComBase.WindowsDeleteString(hstring); },
}