@node-ctypes/comtypes 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +50 -624
  2. package/dist/automation/dispatch.js +10 -3
  3. package/dist/automation/record.js +3 -1
  4. package/dist/automation/variant.d.ts +4 -4
  5. package/dist/automation/variant.js +93 -28
  6. package/dist/client/dynamic.js +7 -8
  7. package/dist/client/events.js +18 -2
  8. package/dist/client/index.js +3 -1
  9. package/dist/commethod.d.ts +1 -1
  10. package/dist/commethod.js +151 -57
  11. package/dist/errorinfo.d.ts +10 -3
  12. package/dist/errorinfo.js +66 -18
  13. package/dist/errors.d.ts +7 -1
  14. package/dist/executor/apartment.d.ts +7 -3
  15. package/dist/executor/apartment.js +65 -29
  16. package/dist/executor/executor.d.ts +2 -0
  17. package/dist/executor/executor.js +65 -14
  18. package/dist/guid.d.ts +1 -1
  19. package/dist/guid.js +7 -9
  20. package/dist/index.d.ts +5 -5
  21. package/dist/index.js +4 -4
  22. package/dist/interfaces/agile.d.ts +52 -0
  23. package/dist/interfaces/agile.js +59 -0
  24. package/dist/interfaces/errorinfo.d.ts +8 -0
  25. package/dist/interfaces/errorinfo.js +10 -0
  26. package/dist/interfaces/index.d.ts +2 -1
  27. package/dist/interfaces/index.js +2 -1
  28. package/dist/low-level/iids.d.ts +14 -0
  29. package/dist/low-level/iids.js +14 -0
  30. package/dist/low-level/index.d.ts +2 -2
  31. package/dist/low-level/index.js +1 -1
  32. package/dist/low-level/native.d.ts +13 -0
  33. package/dist/low-level/native.js +33 -0
  34. package/dist/low-level/registry.js +4 -2
  35. package/dist/low-level/vtable.d.ts +10 -0
  36. package/dist/low-level/vtable.js +32 -5
  37. package/dist/pointer.d.ts +2 -0
  38. package/dist/pointer.js +154 -84
  39. package/dist/pump.d.ts +32 -8
  40. package/dist/pump.js +87 -15
  41. package/dist/runtime.d.ts +6 -0
  42. package/dist/runtime.js +15 -1
  43. package/dist/server/automation.js +3 -3
  44. package/dist/server/comobject.d.ts +53 -0
  45. package/dist/server/comobject.js +319 -27
  46. package/dist/server/index.d.ts +1 -1
  47. package/dist/server/index.js +1 -1
  48. package/dist/server/marshal.d.ts +1 -0
  49. package/dist/server/marshal.js +13 -7
  50. package/dist/server/register.js +8 -6
  51. package/dist/tracking.d.ts +2 -0
  52. package/dist/tracking.js +13 -0
  53. package/package.json +6 -2
@@ -0,0 +1,52 @@
1
+ import * as ctypes from "node-ctypes";
2
+ import { GUID } from "../guid.ts";
3
+ import type { InterfaceDef, InterfacePointer } from "../interface.ts";
4
+ import { COMPointer } from "../pointer.ts";
5
+ /**
6
+ * Marker interface declaring that a COM/WinRT object is agile (callable from
7
+ * any apartment without marshaling).
8
+ */
9
+ export declare const IAgileObject: import("../interface.ts").ComInterfaceDef<import("../interface.ts").ComInterfaceDef<undefined, readonly [import("../interface.ts").MethodSpec<"QueryInterface", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"int32"> & {
10
+ _isHResult: true;
11
+ }, readonly [ctypes.PointerTypeDef<typeof GUID>, ctypes.PointerTypeDef<ctypes.SimpleCDataConstructor<"pointer">>]>, "method", "QueryInterface">, import("../interface.ts").MethodSpec<"AddRef", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"uint32">, readonly []>, "method", "AddRef">, import("../interface.ts").MethodSpec<"Release", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"uint32">, readonly []>, "method", "Release">], readonly []>, readonly [], readonly []>;
12
+ /**
13
+ * Weak reference to a COM/WinRT object (`IWeakReference`). Call
14
+ * {@link resolveWeakReference} (or `Resolve`) to obtain a strong pointer while
15
+ * the target is still alive (`null` once its reference count has reached zero).
16
+ */
17
+ export declare const IWeakReference: import("../interface.ts").ComInterfaceDef<import("../interface.ts").ComInterfaceDef<undefined, readonly [import("../interface.ts").MethodSpec<"QueryInterface", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"int32"> & {
18
+ _isHResult: true;
19
+ }, readonly [ctypes.PointerTypeDef<typeof GUID>, ctypes.PointerTypeDef<ctypes.SimpleCDataConstructor<"pointer">>]>, "method", "QueryInterface">, import("../interface.ts").MethodSpec<"AddRef", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"uint32">, readonly []>, "method", "AddRef">, import("../interface.ts").MethodSpec<"Release", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"uint32">, readonly []>, "method", "Release">], readonly []>, readonly [import("../interface.ts").MethodSpec<"Resolve", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"int32"> & {
20
+ _isHResult: true;
21
+ }, readonly [ctypes.PointerTypeDef<typeof GUID>, ctypes.PointerTypeDef<ctypes.SimpleCDataConstructor<"pointer">>]>, "method", "Resolve">], readonly []>;
22
+ /** Exposes a weak reference to a COM/WinRT object (`IWeakReferenceSource`). */
23
+ export declare const IWeakReferenceSource: import("../interface.ts").ComInterfaceDef<import("../interface.ts").ComInterfaceDef<undefined, readonly [import("../interface.ts").MethodSpec<"QueryInterface", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"int32"> & {
24
+ _isHResult: true;
25
+ }, readonly [ctypes.PointerTypeDef<typeof GUID>, ctypes.PointerTypeDef<ctypes.SimpleCDataConstructor<"pointer">>]>, "method", "QueryInterface">, import("../interface.ts").MethodSpec<"AddRef", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"uint32">, readonly []>, "method", "AddRef">, import("../interface.ts").MethodSpec<"Release", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"uint32">, readonly []>, "method", "Release">], readonly []>, readonly [import("../commethod.ts").CommethodSpec<readonly [], ctypes.SimpleCDataConstructor<"int32"> & {
26
+ _isHResult: true;
27
+ }, "GetWeakReference", readonly [readonly [readonly ["out", "retval"], import("../interface.ts").ComInterfaceDef<import("../interface.ts").ComInterfaceDef<undefined, readonly [import("../interface.ts").MethodSpec<"QueryInterface", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"int32"> & {
28
+ _isHResult: true;
29
+ }, readonly [ctypes.PointerTypeDef<typeof GUID>, ctypes.PointerTypeDef<ctypes.SimpleCDataConstructor<"pointer">>]>, "method", "QueryInterface">, import("../interface.ts").MethodSpec<"AddRef", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"uint32">, readonly []>, "method", "AddRef">, import("../interface.ts").MethodSpec<"Release", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"uint32">, readonly []>, "method", "Release">], readonly []>, readonly [import("../interface.ts").MethodSpec<"Resolve", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"int32"> & {
30
+ _isHResult: true;
31
+ }, readonly [ctypes.PointerTypeDef<typeof GUID>, ctypes.PointerTypeDef<ctypes.SimpleCDataConstructor<"pointer">>]>, "method", "Resolve">], readonly []>, "weakReference"]]>], readonly []>;
32
+ /** Custom marshaling interface (`IMarshal`), including the Free-Threaded Marshaler. */
33
+ export declare const IMarshal: import("../interface.ts").ComInterfaceDef<import("../interface.ts").ComInterfaceDef<undefined, readonly [import("../interface.ts").MethodSpec<"QueryInterface", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"int32"> & {
34
+ _isHResult: true;
35
+ }, readonly [ctypes.PointerTypeDef<typeof GUID>, ctypes.PointerTypeDef<ctypes.SimpleCDataConstructor<"pointer">>]>, "method", "QueryInterface">, import("../interface.ts").MethodSpec<"AddRef", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"uint32">, readonly []>, "method", "AddRef">, import("../interface.ts").MethodSpec<"Release", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"uint32">, readonly []>, "method", "Release">], readonly []>, readonly [import("../interface.ts").MethodSpec<"GetUnmarshalClass", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"int32"> & {
36
+ _isHResult: true;
37
+ }, readonly [ctypes.PointerTypeDef<typeof GUID>, ctypes.SimpleCDataConstructor<"pointer">, ctypes.SimpleCDataConstructor<"uint32">, ctypes.SimpleCDataConstructor<"pointer">, ctypes.SimpleCDataConstructor<"uint32">, ctypes.PointerTypeDef<typeof GUID>]>, "method", "GetUnmarshalClass">, import("../interface.ts").MethodSpec<"GetMarshalSizeMax", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"int32"> & {
38
+ _isHResult: true;
39
+ }, readonly [ctypes.PointerTypeDef<typeof GUID>, ctypes.SimpleCDataConstructor<"pointer">, ctypes.SimpleCDataConstructor<"uint32">, ctypes.SimpleCDataConstructor<"pointer">, ctypes.SimpleCDataConstructor<"uint32">, ctypes.PointerTypeDef<ctypes.SimpleCDataConstructor<"uint32">>]>, "method", "GetMarshalSizeMax">, import("../interface.ts").MethodSpec<"MarshalInterface", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"int32"> & {
40
+ _isHResult: true;
41
+ }, readonly [ctypes.SimpleCDataConstructor<"pointer">, ctypes.PointerTypeDef<typeof GUID>, ctypes.SimpleCDataConstructor<"pointer">, ctypes.SimpleCDataConstructor<"uint32">, ctypes.SimpleCDataConstructor<"pointer">, ctypes.SimpleCDataConstructor<"uint32">]>, "method", "MarshalInterface">, import("../interface.ts").MethodSpec<"UnmarshalInterface", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"int32"> & {
42
+ _isHResult: true;
43
+ }, readonly [ctypes.SimpleCDataConstructor<"pointer">, ctypes.PointerTypeDef<typeof GUID>, ctypes.PointerTypeDef<ctypes.SimpleCDataConstructor<"pointer">>]>, "method", "UnmarshalInterface">, import("../interface.ts").MethodSpec<"ReleaseMarshalData", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"int32"> & {
44
+ _isHResult: true;
45
+ }, readonly [ctypes.SimpleCDataConstructor<"pointer">]>, "method", "ReleaseMarshalData">, import("../interface.ts").MethodSpec<"DisconnectObject", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"int32"> & {
46
+ _isHResult: true;
47
+ }, readonly [ctypes.SimpleCDataConstructor<"uint32">]>, "method", "DisconnectObject">], readonly []>;
48
+ /**
49
+ * Resolve an `IWeakReference` to a strong typed pointer for `iface`, or `null`
50
+ * if the target object has already been released.
51
+ */
52
+ export declare function resolveWeakReference<T extends InterfaceDef<any>>(weak: COMPointer<typeof IWeakReference>, iface: T): InterfacePointer<T> | null;
@@ -0,0 +1,59 @@
1
+ import * as ctypes from "node-ctypes";
2
+ import { COMMETHOD } from "../commethod.js";
3
+ import { checkHRESULT } from "../errors.js";
4
+ import { GUID } from "../guid.js";
5
+ import { COMInterface, HRESULT, STDMETHOD } from "../interface.js";
6
+ import { COMPointer, sync } from "../pointer.js";
7
+ import { IUnknown } from "./unknown.js";
8
+ const { c_uint32, c_void_p, POINTER } = ctypes;
9
+ /**
10
+ * Marker interface declaring that a COM/WinRT object is agile (callable from
11
+ * any apartment without marshaling).
12
+ */
13
+ export const IAgileObject = COMInterface({
14
+ name: "IAgileObject",
15
+ iid: "{94EA2B94-E9CC-49E0-C0FF-EE64CA8F5B90}",
16
+ extends: IUnknown,
17
+ methods: [],
18
+ });
19
+ /**
20
+ * Weak reference to a COM/WinRT object (`IWeakReference`). Call
21
+ * {@link resolveWeakReference} (or `Resolve`) to obtain a strong pointer while
22
+ * the target is still alive (`null` once its reference count has reached zero).
23
+ */
24
+ export const IWeakReference = COMInterface({
25
+ name: "IWeakReference",
26
+ iid: "{00000037-0000-0000-C000-000000000046}",
27
+ extends: IUnknown,
28
+ methods: [STDMETHOD(HRESULT, "Resolve", [POINTER(GUID), POINTER(c_void_p)])],
29
+ });
30
+ /** Exposes a weak reference to a COM/WinRT object (`IWeakReferenceSource`). */
31
+ export const IWeakReferenceSource = COMInterface({
32
+ name: "IWeakReferenceSource",
33
+ iid: "{00000038-0000-0000-C000-000000000046}",
34
+ extends: IUnknown,
35
+ methods: [COMMETHOD([], HRESULT, "GetWeakReference", [["out", "retval"], IWeakReference, "weakReference"])],
36
+ });
37
+ /** Custom marshaling interface (`IMarshal`), including the Free-Threaded Marshaler. */
38
+ export const IMarshal = COMInterface({
39
+ name: "IMarshal",
40
+ iid: "{00000003-0000-0000-C000-000000000046}",
41
+ extends: IUnknown,
42
+ methods: [
43
+ STDMETHOD(HRESULT, "GetUnmarshalClass", [POINTER(GUID), c_void_p, c_uint32, c_void_p, c_uint32, POINTER(GUID)]),
44
+ STDMETHOD(HRESULT, "GetMarshalSizeMax", [POINTER(GUID), c_void_p, c_uint32, c_void_p, c_uint32, POINTER(c_uint32)]),
45
+ STDMETHOD(HRESULT, "MarshalInterface", [c_void_p, POINTER(GUID), c_void_p, c_uint32, c_void_p, c_uint32]),
46
+ STDMETHOD(HRESULT, "UnmarshalInterface", [c_void_p, POINTER(GUID), POINTER(c_void_p)]),
47
+ STDMETHOD(HRESULT, "ReleaseMarshalData", [c_void_p]),
48
+ STDMETHOD(HRESULT, "DisconnectObject", [c_uint32]),
49
+ ],
50
+ });
51
+ /**
52
+ * Resolve an `IWeakReference` to a strong typed pointer for `iface`, or `null`
53
+ * if the target object has already been released.
54
+ */
55
+ export function resolveWeakReference(weak, iface) {
56
+ const out = new c_void_p();
57
+ checkHRESULT(sync(weak).Resolve(iface.iid._buffer, ctypes.byref(out)), "IWeakReference::Resolve");
58
+ return out.value ? COMPointer.fromAddress(out.value, iface) : null;
59
+ }
@@ -32,3 +32,11 @@ export declare const ISupportErrorInfo: import("../interface.ts").ComInterfaceDe
32
32
  }, readonly [ctypes.PointerTypeDef<typeof GUID>, ctypes.PointerTypeDef<ctypes.SimpleCDataConstructor<"pointer">>]>, "method", "QueryInterface">, import("../interface.ts").MethodSpec<"AddRef", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"uint32">, readonly []>, "method", "AddRef">, import("../interface.ts").MethodSpec<"Release", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"uint32">, readonly []>, "method", "Release">], readonly []>, readonly [import("../commethod.ts").CommethodSpec<readonly [], ctypes.SimpleCDataConstructor<"int32"> & {
33
33
  _isHResult: true;
34
34
  }, "InterfaceSupportsErrorInfo", readonly [readonly [readonly ["in"], import("../commethod.ts").RefGuidType, "riid"]]>], readonly []>;
35
+ /** WinRT / modern COM restricted error object (`GetRestrictedErrorInfo` / `RoOriginateErrorW`). */
36
+ export declare const IRestrictedErrorInfo: import("../interface.ts").ComInterfaceDef<import("../interface.ts").ComInterfaceDef<undefined, readonly [import("../interface.ts").MethodSpec<"QueryInterface", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"int32"> & {
37
+ _isHResult: true;
38
+ }, readonly [ctypes.PointerTypeDef<typeof GUID>, ctypes.PointerTypeDef<ctypes.SimpleCDataConstructor<"pointer">>]>, "method", "QueryInterface">, import("../interface.ts").MethodSpec<"AddRef", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"uint32">, readonly []>, "method", "AddRef">, import("../interface.ts").MethodSpec<"Release", import("../interface.ts").RawFunction<ctypes.SimpleCDataConstructor<"uint32">, readonly []>, "method", "Release">], readonly []>, readonly [import("../commethod.ts").CommethodSpec<readonly [], ctypes.SimpleCDataConstructor<"int32"> & {
39
+ _isHResult: true;
40
+ }, "GetErrorDetails", readonly [readonly [readonly ["out"], import("../commethod.ts").BSTRType, "description"], readonly [readonly ["out"], ctypes.SimpleCDataConstructor<"int32">, "error"], readonly [readonly ["out"], import("../commethod.ts").BSTRType, "restrictedDescription"], readonly [readonly ["out"], import("../commethod.ts").BSTRType, "capabilitySid"]]>, import("../commethod.ts").CommethodSpec<readonly [], ctypes.SimpleCDataConstructor<"int32"> & {
41
+ _isHResult: true;
42
+ }, "GetReference", readonly [readonly [readonly ["out"], import("../commethod.ts").BSTRType, "reference"]]>], readonly []>;
@@ -35,3 +35,13 @@ export const ISupportErrorInfo = COMInterface({
35
35
  extends: IUnknown,
36
36
  methods: [COMMETHOD([], HRESULT, "InterfaceSupportsErrorInfo", [["in"], REFIID, "riid"])],
37
37
  });
38
+ /** WinRT / modern COM restricted error object (`GetRestrictedErrorInfo` / `RoOriginateErrorW`). */
39
+ export const IRestrictedErrorInfo = COMInterface({
40
+ name: "IRestrictedErrorInfo",
41
+ iid: "{82BA7092-4C88-427D-A7BC-16DD93FEB67E}",
42
+ extends: IUnknown,
43
+ methods: [
44
+ COMMETHOD([], HRESULT, "GetErrorDetails", [["out"], BSTR, "description"], [["out"], ctypes.c_int32, "error"], [["out"], BSTR, "restrictedDescription"], [["out"], BSTR, "capabilitySid"]),
45
+ COMMETHOD([], HRESULT, "GetReference", [["out"], BSTR, "reference"]),
46
+ ],
47
+ });
@@ -1,5 +1,6 @@
1
1
  export { IUnknown, IID_IUnknown } from "./unknown.ts";
2
- export { IErrorInfo, ICreateErrorInfo, ISupportErrorInfo } from "./errorinfo.ts";
2
+ export { IAgileObject, IWeakReference, IWeakReferenceSource, IMarshal, resolveWeakReference } from "./agile.ts";
3
+ export { IErrorInfo, ICreateErrorInfo, ISupportErrorInfo, IRestrictedErrorInfo } from "./errorinfo.ts";
3
4
  export { IPersist, IPersistFile, STGM_READ, STGM_WRITE, STGM_READWRITE, IErrorLog, IPropertyBag, IPersistPropertyBag, IPropertyBag2, IPersistPropertyBag2, PROPBAG2, PROPBAG2_TYPE_UNDEFINED, PROPBAG2_TYPE_DATA, PROPBAG2_TYPE_URL, PROPBAG2_TYPE_OBJECT, PROPBAG2_TYPE_STREAM, PROPBAG2_TYPE_STORAGE, PROPBAG2_TYPE_MONIKER, } from "./persist.ts";
4
5
  export { IServiceProvider, queryService } from "./servprov.ts";
5
6
  export { IViewObject, IViewObject2, SIZEL, DVASPECT_CONTENT, DVASPECT_THUMBNAIL, DVASPECT_ICON, DVASPECT_DOCPRINT } from "./viewobject.ts";
@@ -1,5 +1,6 @@
1
1
  export { IUnknown, IID_IUnknown } from "./unknown.js";
2
- export { IErrorInfo, ICreateErrorInfo, ISupportErrorInfo } from "./errorinfo.js";
2
+ export { IAgileObject, IWeakReference, IWeakReferenceSource, IMarshal, resolveWeakReference } from "./agile.js";
3
+ export { IErrorInfo, ICreateErrorInfo, ISupportErrorInfo, IRestrictedErrorInfo } from "./errorinfo.js";
3
4
  export { IPersist, IPersistFile, STGM_READ, STGM_WRITE, STGM_READWRITE, IErrorLog, IPropertyBag, IPersistPropertyBag, IPropertyBag2, IPersistPropertyBag2, PROPBAG2, PROPBAG2_TYPE_UNDEFINED, PROPBAG2_TYPE_DATA, PROPBAG2_TYPE_URL, PROPBAG2_TYPE_OBJECT, PROPBAG2_TYPE_STREAM, PROPBAG2_TYPE_STORAGE, PROPBAG2_TYPE_MONIKER, } from "./persist.js";
4
5
  export { IServiceProvider, queryService } from "./servprov.js";
5
6
  export { IViewObject, IViewObject2, SIZEL, DVASPECT_CONTENT, DVASPECT_THUMBNAIL, DVASPECT_ICON, DVASPECT_DOCPRINT } from "./viewobject.js";
@@ -0,0 +1,14 @@
1
+ import { GUID } from "../guid.ts";
2
+ /** Shared well-known COM IIDs / CLSIDs used internally across modules. */
3
+ export declare const IID_IUnknown: GUID;
4
+ export declare const IID_IDispatch: GUID;
5
+ export declare const IID_ISupportErrorInfo: GUID;
6
+ export declare const IID_IRestrictedErrorInfo: GUID;
7
+ export declare const IID_IAgileObject: GUID;
8
+ export declare const IID_IWeakReference: GUID;
9
+ export declare const IID_IWeakReferenceSource: GUID;
10
+ export declare const IID_IMarshal: GUID;
11
+ export declare const IID_IClientSecurity: GUID;
12
+ export declare const IID_IGlobalInterfaceTable: GUID;
13
+ export declare const CLSID_StdGlobalInterfaceTable: GUID;
14
+ export declare const CLSID_InProcFreeMarshaler: GUID;
@@ -0,0 +1,14 @@
1
+ import { GUID } from "../guid.js";
2
+ /** Shared well-known COM IIDs / CLSIDs used internally across modules. */
3
+ export const IID_IUnknown = new GUID("{00000000-0000-0000-C000-000000000046}");
4
+ export const IID_IDispatch = new GUID("{00020400-0000-0000-C000-000000000046}");
5
+ export const IID_ISupportErrorInfo = new GUID("{DF0B3D60-548F-101B-8E65-08002B2BD119}");
6
+ export const IID_IRestrictedErrorInfo = new GUID("{82BA7092-4C88-427D-A7BC-16DD93FEB67E}");
7
+ export const IID_IAgileObject = new GUID("{94EA2B94-E9CC-49E0-C0FF-EE64CA8F5B90}");
8
+ export const IID_IWeakReference = new GUID("{00000037-0000-0000-C000-000000000046}");
9
+ export const IID_IWeakReferenceSource = new GUID("{00000038-0000-0000-C000-000000000046}");
10
+ export const IID_IMarshal = new GUID("{00000003-0000-0000-C000-000000000046}");
11
+ export const IID_IClientSecurity = new GUID("{0000013D-0000-0000-C000-000000000046}");
12
+ export const IID_IGlobalInterfaceTable = new GUID("{00000146-0000-0000-C000-000000000046}");
13
+ export const CLSID_StdGlobalInterfaceTable = new GUID("{00000323-0000-0000-C000-000000000046}");
14
+ export const CLSID_InProcFreeMarshaler = new GUID("{0000033A-0000-0000-C000-000000000046}");
@@ -1,5 +1,5 @@
1
- export { ole32, oleaut32, allocBSTR, readBSTR, takeBSTR, takeCoTaskMemString, readMemory, writeMemory, isWindows, POINTER_SIZE } from "./native.ts";
2
- export type { Ole32, OleAut32 } from "./native.ts";
1
+ export { ole32, oleaut32, combase, allocBSTR, readBSTR, takeBSTR, takeCoTaskMemString, readMemory, writeMemory, isWindows, POINTER_SIZE } from "./native.ts";
2
+ export type { Ole32, OleAut32, Combase } from "./native.ts";
3
3
  export { vtableEntry, functionCache, rawQueryInterface, rawAddRef, rawRelease } from "./vtable.ts";
4
4
  export { executorCall, executorGeneration } from "../executor/executor.ts";
5
5
  export type { CallOptions, NativeCall, NativeResult } from "../executor/executor.ts";
@@ -1,4 +1,4 @@
1
- export { ole32, oleaut32, allocBSTR, readBSTR, takeBSTR, takeCoTaskMemString, readMemory, writeMemory, isWindows, POINTER_SIZE } from "./native.js";
1
+ export { ole32, oleaut32, combase, allocBSTR, readBSTR, takeBSTR, takeCoTaskMemString, readMemory, writeMemory, isWindows, POINTER_SIZE } from "./native.js";
2
2
  export { vtableEntry, functionCache, rawQueryInterface, rawAddRef, rawRelease } from "./vtable.js";
3
3
  export { executorCall, executorGeneration } from "../executor/executor.js";
4
4
  export { COSERVERINFO, MULTI_QI } from "./types.js";
@@ -1,6 +1,10 @@
1
1
  import * as ctypes from "node-ctypes";
2
2
  export declare const POINTER_SIZE: number;
3
3
  export declare const isWindows: boolean;
4
+ /** Whether `type` is a `node-ctypes` `Structure` or `Union` class. */
5
+ export declare function isAggregateClass(type: unknown): type is new (...args: any[]) => ctypes.CDataAggregate;
6
+ /** Whether `type` is a `node-ctypes` `POINTER(T)` class/definition. */
7
+ export declare function isPointerType(type: unknown): type is ctypes.PointerTypeDef;
4
8
  declare function bindOle32(library: ctypes.WinDLL): {
5
9
  CoInitializeEx: ctypes.TypedFFIFunction<readonly [ctypes.SimpleCDataConstructor<"pointer">, ctypes.SimpleCDataConstructor<"uint32">], ctypes.SimpleCDataConstructor<"int32">>;
6
10
  CoUninitialize: ctypes.TypedFFIFunction<readonly [], null>;
@@ -22,6 +26,12 @@ declare function bindOle32(library: ctypes.WinDLL): {
22
26
  CoWaitForMultipleHandles: ctypes.TypedFFIFunction<readonly [ctypes.SimpleCDataConstructor<"uint32">, ctypes.SimpleCDataConstructor<"uint32">, ctypes.SimpleCDataConstructor<"uint32">, ctypes.SimpleCDataConstructor<"pointer">, ctypes.SimpleCDataConstructor<"pointer">], ctypes.SimpleCDataConstructor<"int32">>;
23
27
  CoRegisterClassObject: ctypes.TypedFFIFunction<readonly [ctypes.SimpleCDataConstructor<"pointer">, ctypes.SimpleCDataConstructor<"pointer">, ctypes.SimpleCDataConstructor<"uint32">, ctypes.SimpleCDataConstructor<"uint32">, ctypes.SimpleCDataConstructor<"pointer">], ctypes.SimpleCDataConstructor<"int32">>;
24
28
  CoRevokeClassObject: ctypes.TypedFFIFunction<readonly [ctypes.SimpleCDataConstructor<"uint32">], ctypes.SimpleCDataConstructor<"int32">>;
29
+ CoCreateFreeThreadedMarshaler: ctypes.TypedFFIFunction<readonly [ctypes.SimpleCDataConstructor<"pointer">, ctypes.SimpleCDataConstructor<"pointer">], ctypes.SimpleCDataConstructor<"int32">>;
30
+ };
31
+ declare function bindCombase(library: ctypes.WinDLL): {
32
+ GetRestrictedErrorInfo: ctypes.TypedFFIFunction<readonly [ctypes.SimpleCDataConstructor<"pointer">], ctypes.SimpleCDataConstructor<"int32">>;
33
+ SetRestrictedErrorInfo: ctypes.TypedFFIFunction<readonly [ctypes.SimpleCDataConstructor<"pointer">], ctypes.SimpleCDataConstructor<"int32">>;
34
+ RoOriginateErrorW: ctypes.TypedFFIFunction<readonly [ctypes.SimpleCDataConstructor<"int32">, ctypes.SimpleCDataConstructor<"uint32">, ctypes.SimpleCDataConstructor<"wstring">], ctypes.SimpleCDataConstructor<"int32">>;
25
35
  };
26
36
  declare function bindOleAut32(library: ctypes.WinDLL): {
27
37
  GetErrorInfo: ctypes.TypedFFIFunction<readonly [ctypes.SimpleCDataConstructor<"uint32">, ctypes.SimpleCDataConstructor<"pointer">], ctypes.SimpleCDataConstructor<"int32">>;
@@ -60,10 +70,13 @@ declare function bindOleAut32(library: ctypes.WinDLL): {
60
70
  };
61
71
  export type Ole32 = ReturnType<typeof bindOle32>;
62
72
  export type OleAut32 = ReturnType<typeof bindOleAut32>;
73
+ export type Combase = ReturnType<typeof bindCombase>;
63
74
  /** ole32.dll functions, loaded on first use. */
64
75
  export declare function ole32(): Ole32;
65
76
  /** oleaut32.dll functions, loaded on first use. */
66
77
  export declare function oleaut32(): OleAut32;
78
+ /** combase.dll functions (WinRT / restricted error info), loaded on first use; `null` if unavailable. */
79
+ export declare function combase(): Combase | null;
67
80
  /** Allocate a BSTR (embedded NULs preserved). Free it with `SysFreeString`. */
68
81
  export declare function allocBSTR(text: string): bigint;
69
82
  /** Read a BSTR without freeing it (`null` for a NULL BSTR, which COM treats as ""). */
@@ -2,6 +2,15 @@ import * as ctypes from "node-ctypes";
2
2
  const { c_int32, c_uint16, c_uint32, c_void_p, c_wchar_p, c_size_t } = ctypes;
3
3
  export const POINTER_SIZE = ctypes.sizeof(c_void_p);
4
4
  export const isWindows = process.platform === "win32";
5
+ /** Whether `type` is a `node-ctypes` `Structure` or `Union` class. */
6
+ export function isAggregateClass(type) {
7
+ return typeof type === "function" && (type.prototype instanceof ctypes.Structure || type.prototype instanceof ctypes.Union);
8
+ }
9
+ /** Whether `type` is a `node-ctypes` `POINTER(T)` class/definition. */
10
+ export function isPointerType(type) {
11
+ // POINTER(T) is a class (as in CPython); _pointerTo is undefined on other types.
12
+ return (typeof type === "function" || (typeof type === "object" && type !== null)) && type._pointerTo !== undefined;
13
+ }
5
14
  // HRESULT-returning functions are bound with `c_int32` (not `HRESULT`): the
6
15
  // raw value is returned and checked by the caller, which builds a COMError.
7
16
  function bindOle32(library) {
@@ -26,6 +35,14 @@ function bindOle32(library) {
26
35
  CoWaitForMultipleHandles: library.func("CoWaitForMultipleHandles", c_int32, [c_uint32, c_uint32, c_uint32, c_void_p, c_void_p]),
27
36
  CoRegisterClassObject: library.func("CoRegisterClassObject", c_int32, [c_void_p, c_void_p, c_uint32, c_uint32, c_void_p]),
28
37
  CoRevokeClassObject: library.func("CoRevokeClassObject", c_int32, [c_uint32]),
38
+ CoCreateFreeThreadedMarshaler: library.func("CoCreateFreeThreadedMarshaler", c_int32, [c_void_p, c_void_p]),
39
+ };
40
+ }
41
+ function bindCombase(library) {
42
+ return {
43
+ GetRestrictedErrorInfo: library.func("GetRestrictedErrorInfo", c_int32, [c_void_p]),
44
+ SetRestrictedErrorInfo: library.func("SetRestrictedErrorInfo", c_int32, [c_void_p]),
45
+ RoOriginateErrorW: library.func("RoOriginateErrorW", c_int32, [c_int32, c_uint32, c_wchar_p]),
29
46
  };
30
47
  }
31
48
  function bindOleAut32(library) {
@@ -67,6 +84,8 @@ function bindOleAut32(library) {
67
84
  }
68
85
  let ole32Functions = null;
69
86
  let oleaut32Functions = null;
87
+ let combaseFunctions = null;
88
+ let combaseUnavailable = false;
70
89
  function requireWindows() {
71
90
  if (!isWindows)
72
91
  throw new Error(`COM is only available on Windows (current platform: ${process.platform})`);
@@ -81,6 +100,20 @@ export function oleaut32() {
81
100
  requireWindows();
82
101
  return (oleaut32Functions ??= bindOleAut32(new ctypes.WinDLL("oleaut32.dll")));
83
102
  }
103
+ /** combase.dll functions (WinRT / restricted error info), loaded on first use; `null` if unavailable. */
104
+ export function combase() {
105
+ if (!isWindows || combaseUnavailable)
106
+ return null;
107
+ if (combaseFunctions)
108
+ return combaseFunctions;
109
+ try {
110
+ return (combaseFunctions = bindCombase(new ctypes.WinDLL("combase.dll")));
111
+ }
112
+ catch {
113
+ combaseUnavailable = true;
114
+ return null;
115
+ }
116
+ }
84
117
  /** Allocate a BSTR (embedded NULs preserved). Free it with `SysFreeString`. */
85
118
  export function allocBSTR(text) {
86
119
  const pointer = oleaut32().SysAllocStringLen(Buffer.from(text, "utf16le"), text.length);
@@ -53,9 +53,11 @@ export function subkeys(root, key) {
53
53
  try {
54
54
  const names = [];
55
55
  const name = Buffer.alloc(512);
56
+ const length = new ctypes.c_uint32();
57
+ const lengthRef = ctypes.byref(length);
56
58
  for (let index = 0;; index++) {
57
- const length = new ctypes.c_uint32(name.length / 2);
58
- const result = api().RegEnumKeyExW(handle.value, index, name, ctypes.byref(length), null, null, null, null);
59
+ length.value = name.length / 2;
60
+ const result = api().RegEnumKeyExW(handle.value, index, name, lengthRef, null, null, null, null);
59
61
  if (result === ERROR_NO_MORE_ITEMS)
60
62
  return names;
61
63
  if (result !== ERROR_SUCCESS)
@@ -1,11 +1,21 @@
1
1
  import * as ctypes from "node-ctypes";
2
+ /** Read the vtable pointer of the COM object at `object`. */
3
+ export declare function vtableOf(object: bigint): bigint;
4
+ /** Address of the function in vtable slot `slot` of `vtable`. */
5
+ export declare function vtableEntryFromTable(vtable: bigint, slot: number): bigint;
2
6
  /** Address of the function in vtable slot `slot` of the COM object at `object`. */
3
7
  export declare function vtableEntry(object: bigint, slot: number): bigint;
8
+ /** Format a native 16-byte GUID at `address` directly into `{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}` without allocating a `GUID` Structure. */
9
+ export declare function readGuidString(address: bigint): string;
4
10
  /**
5
11
  * Bind function pointers of one prototype, cached by address: binding costs
6
12
  * far more than calling, and vtables are shared by all objects of a class.
13
+ * Bounded to prevent unbounded growth in long-running processes with dynamic DLLs.
7
14
  */
8
15
  export declare function functionCache<TRet extends ctypes.FFIType | null, const TArgs extends readonly ctypes.FFIType[]>(prototype: () => ctypes.FuncPtrFactory<TRet, TArgs>): (address: bigint) => ctypes.TypedFFIFunction<TArgs, TRet>;
16
+ export declare const QueryInterfaceAt: (address: bigint) => ctypes.TypedFFIFunction<readonly [ctypes.SimpleCDataConstructor<"pointer">, ctypes.SimpleCDataConstructor<"pointer">, ctypes.SimpleCDataConstructor<"pointer">], ctypes.SimpleCDataConstructor<"int32">>;
17
+ export declare const RefCountAt: (address: bigint) => ctypes.TypedFFIFunction<readonly [ctypes.SimpleCDataConstructor<"pointer">], ctypes.SimpleCDataConstructor<"uint32">>;
18
+ export declare const PointerArgAt: (address: bigint) => ctypes.TypedFFIFunction<readonly [ctypes.SimpleCDataConstructor<"pointer">, ctypes.SimpleCDataConstructor<"pointer">], ctypes.SimpleCDataConstructor<"int32">>;
9
19
  export declare function rawQueryInterface(object: bigint, iid: {
10
20
  readonly _buffer: Buffer;
11
21
  }): [hr: number, pointer: bigint | null];
@@ -1,34 +1,61 @@
1
1
  import * as ctypes from "node-ctypes";
2
2
  import { POINTER_SIZE } from "./native.js";
3
3
  const { c_int32, c_uint32, c_void_p } = ctypes;
4
- /** Address of the function in vtable slot `slot` of the COM object at `object`. */
5
- export function vtableEntry(object, slot) {
4
+ /** Read the vtable pointer of the COM object at `object`. */
5
+ export function vtableOf(object) {
6
6
  if (!object)
7
7
  throw new TypeError("NULL COM pointer");
8
8
  const vtable = ctypes.readValue(object, c_void_p);
9
9
  if (!vtable)
10
10
  throw new TypeError("COM object has a NULL vtable");
11
+ return vtable;
12
+ }
13
+ /** Address of the function in vtable slot `slot` of `vtable`. */
14
+ export function vtableEntryFromTable(vtable, slot) {
11
15
  const entry = ctypes.readValue(vtable, c_void_p, slot * POINTER_SIZE);
12
16
  if (!entry)
13
17
  throw new TypeError(`COM vtable slot ${slot} is NULL`);
14
18
  return entry;
15
19
  }
20
+ /** Address of the function in vtable slot `slot` of the COM object at `object`. */
21
+ export function vtableEntry(object, slot) {
22
+ return vtableEntryFromTable(vtableOf(object), slot);
23
+ }
24
+ const guidScratch = Buffer.allocUnsafe(16);
25
+ /** Format a native 16-byte GUID at `address` directly into `{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}` without allocating a `GUID` Structure. */
26
+ export function readGuidString(address) {
27
+ ctypes.memmove(guidScratch, address, 16);
28
+ const d1 = guidScratch.readUInt32LE(0).toString(16).padStart(8, "0");
29
+ const d2 = guidScratch.readUInt16LE(4).toString(16).padStart(4, "0");
30
+ const d3 = guidScratch.readUInt16LE(6).toString(16).padStart(4, "0");
31
+ const tail = guidScratch.subarray(8, 16).toString("hex");
32
+ return `{${d1}-${d2}-${d3}-${tail.slice(0, 4)}-${tail.slice(4)}}`.toUpperCase();
33
+ }
34
+ const MAX_FUNCTION_CACHE = 4096;
16
35
  /**
17
36
  * Bind function pointers of one prototype, cached by address: binding costs
18
37
  * far more than calling, and vtables are shared by all objects of a class.
38
+ * Bounded to prevent unbounded growth in long-running processes with dynamic DLLs.
19
39
  */
20
40
  export function functionCache(prototype) {
21
41
  let factory = null;
22
42
  const cache = new Map();
23
43
  return (address) => {
24
44
  let fn = cache.get(address);
25
- if (!fn)
45
+ if (!fn) {
46
+ if (cache.size >= MAX_FUNCTION_CACHE) {
47
+ const oldest = cache.keys().next().value;
48
+ if (oldest !== undefined)
49
+ cache.delete(oldest);
50
+ }
26
51
  cache.set(address, (fn = (factory ??= prototype())(address)));
52
+ }
27
53
  return fn;
28
54
  };
29
55
  }
30
- const QueryInterfaceAt = functionCache(() => ctypes.WINFUNCTYPE(c_int32, c_void_p, c_void_p, c_void_p));
31
- const RefCountAt = functionCache(() => ctypes.WINFUNCTYPE(c_uint32, c_void_p));
56
+ export const QueryInterfaceAt = functionCache(() => ctypes.WINFUNCTYPE(c_int32, c_void_p, c_void_p, c_void_p));
57
+ export const RefCountAt = functionCache(() => ctypes.WINFUNCTYPE(c_uint32, c_void_p));
58
+ export const PointerArgAt = functionCache(() => ctypes.WINFUNCTYPE(c_int32, c_void_p, c_void_p));
32
59
  // Raw IUnknown calls without errcheck: used by error handling, finalizers
33
60
  // and lifetime tracking, where throwing or recursion is not acceptable.
34
61
  export function rawQueryInterface(object, iid) {
package/dist/pointer.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { Operation } from "./executor/operations.ts";
3
3
  import { GUID } from "./guid.ts";
4
4
  import type { InterfaceDef, InterfacePointer, MethodSpec, SyncPointer } from "./interface.ts";
5
5
  type Callable = (...args: any[]) => any;
6
+ declare const COM_POINTER_BRAND: unique symbol;
6
7
  /** How an asynchronous call reaches the executor. */
7
8
  export interface AsyncContext {
8
9
  /** The home thread is single-threaded: interface results are handed back to it. */
@@ -92,6 +93,7 @@ export declare function sync<I extends InterfaceDef<any>>(pointer: COMPointer<I>
92
93
  */
93
94
  export declare class COMPointer<I extends InterfaceDef = InterfaceDef> implements Disposable {
94
95
  #private;
96
+ readonly [COM_POINTER_BRAND] = true;
95
97
  readonly interface: I;
96
98
  constructor(address: bigint, iface: I);
97
99
  /** Wrap a raw interface pointer. */