Calls the DotNetBridge.dll COM component registered on the machine and exposes namespaces and types.
const CLR = require("../common/dotnet");
const System = new CLR.Namespace("System");
// and then call any API like so:
System.Threading.Thread.Sleep(1000);
System.Diagnostics.Trace.WriteLine("hello");
Event handlers:
var eventToken = System.AppDomain.CurrentDomain.AssemblyLoad += new System.AssemblyLoadEventHandler(function (s, e) { asmLoaded = true;});
Connect Trace.WriteLine()
to write to console.log()
for debugging purposes:
const CLRDebug = require('../common/DotNet-debug');
CLRDebug.EnableTraceListener();
Returns win64
or stdcall
.
Read and write GUID data:
var guidPtr = GUID.alloc("{6fdf6ffc-ed77-94fa-407e-a7b86ed9e59d}");
var guidStr = GUID.read(guidPtr);
Create a BROWSEINFOW struct at browseinfoPtr
:
var browseinfo = new Struct({
'hwndOwner':'int',
'pidlRoot':'pointer',
'pszDisplayName':'pointer',
'lpszTitle':'pointer',
'ulFlags':'uint',
'lpfn':'pointer',
'lParam':'long',
'iImage':'int',
}, browseinfoPtr);
Then read or write as javascript object properties:
console.log("Flags: 0x" + browseinfo.ulFlags.toString(16));
WinRT.Initialize(); // RO_INIT_MULTITHREADED
var coreApplication = WinRT.GetActivationFactory("Windows.ApplicationModel.Core.CoreApplication", ICoreImmersiveApplication);
var mainView = new COM.Pointer(ICoreApplicationView);
ThrowIfFailed(coreApplication.get_MainView(mainView.GetAddressOf()));
TODO
TODO
Initialize COM (CoInitialize)
COM.Initialize(COM.ApartmentType.STA);
Create objects with defined interfaces.
var IFileDialog = new COM.Interface(COM.IUnknown, {
Show: [0, ['uint']],
SetOptions: [6, ['uint']],
GetResult: [17, ['pointer']],
}, "42f85136-db7e-439c-85f1-e4075d135fc8");
var modalWindow = COM.CreateInstance(CLSID_FileOpenDialog, COM.ClassContext.InProc, IFileDialog);
Misc COM constants, enums and interfaces:
COM.S_OK
COM.S_FALSE
COM.E_NOINTERFACE
COM.ApartmentType.STA // or MTA
COM.ClassContext.InProc // or Local
COM.IUnknown
COM.IInspectable
if (COM.Succeeded(CallSomeComApi())) {
// call succeeded.
}
if (COM.Failed(CallSomeComApi())) {
// call failed.
}
COM.ThrowIfFailed(CallSomeComApi());
// call succeeded.
var shellItem = new COM.Pointer(IShellItem);
COM.ThrowIfFailed(modalWindow.GetResult(shellItem.GetAddressOf()));
var IFileDialog = new COM.Interface(COM.IUnknown, {
Show: [0, ['uint']],
SetOptions: [6, ['uint']],
GetResult: [17, ['pointer']],
}, "42f85136-db7e-439c-85f1-e4075d135fc8");
var ICoreApplicationView = new COM.Interface(COM.IInspectable, {
get_CoreWindow: [0, ['pointer']],
}, "638BB2DB-451D-4661-B099-414F34FFB9F1");
// Build a callback object.
var dispatcherFrame = new COM.RuntimeObject(IDispatchedHandler.IID);
// HRESULT IDispatchedHandler.Invoke(void);
dispatcherFrame.AddEntry(function (this_ptr) { callback(); return COM.S_OK; }, 'uint', ['pointer']);
ThrowIfFailed(coreDispatcher.RunAsync(CoreDispatcherPriority.Normal, dispatcherFrame.GetAddress(), Memory.alloc(Process.pointerSize)));
Read and write HSTRING data:
var hstr = HSTRING.alloc("plain text");
var hstrStringText = HSTRING.read(hstr);
Read and write BSTR data:
var bstr = BSTR.alloc("plain text");
var bstrStringText = BSTR.read(bstr);
BSTR.free(bstr);