0

Does anyone know how we can use Windows library functions like for example this ms link for ms api? This is given support for .Net supported languages, but is there any way to use these functions in either JavaScript or TypeScript?

For instance, when you have a Discord application installed and you use discord web it prompts you to open in Discord app so most probably it's using the GetProcess Windows library function. So how how can I implement something like that?

I thought I could create an npm package in one of .Net supported languages, but haven't tried that yet. I'm still researching.

Update: Im tyring to use systemMediacontrols in a vs code extension thats what this is for

ninetynin
  • 19
  • 1
  • 6
  • Do you mean in a browser? (If so, no, you can't use Windows API functions.) If not, what environment are you trying to do this in? – T.J. Crowder Oct 15 '22 at 08:34
  • 1
    Just to clarify: [`SystemMediaTransportControls`](https://learn.microsoft.com/en-us/uwp/api/Windows.Media.SystemMediaTransportControls) is a *Windows Runtime* type. It is a native system API that's unrelated to .NET or C#. As far as I understand, consuming WinRT types from JavaScript is officially supported. [Windows Runtime components](https://learn.microsoft.com/en-us/windows/uwp/winrt-components/) has a few walkthroughs that should cover the basics of consuming a WinRT type from JavaScript. – IInspectable Oct 15 '22 at 08:47
  • @T.J.Crowder Im actually tring to build a vs code extension that i what i need this for – ninetynin Oct 15 '22 at 09:17
  • @IInspectable thanks for clarifying i actually didnt change the language option and thought that it is supported in c# only and thought we can use c# or f# or vb for this.. ill check more about it thanks – ninetynin Oct 15 '22 at 09:19
  • A bit of historic background: Back when the Windows Runtime was introduced in Windows 8 the main design goal was to provide an API that's usable by clients written in just about any programming language. First-class support for HTML/CSS/JavaScript had been touted as The major selling point. A decade later we've come to realize: Hardly anyone uses WinRT from JavaScript, and JavaScript support is a monumental road block in progressing the WinRT infrastructure. I suppose that's why you rarely (if ever) find JavaScript in the language selector dropdown of the documentation. – IInspectable Oct 15 '22 at 09:50
  • @IInspectable ye i learnt a bit about these as i never used winrt properly... and found this too [github link](https://github.com/microsoft/Windows-universal-samples/blob/main/archived/SystemMediaTransportControls/js/js/scenario1.js) but when i was trying to use this or do any other thing manually im always getting Windows is not defined error .. there's nothing on internet and github too do u have any idea what it is about thanks – ninetynin Oct 17 '22 at 12:43

1 Answers1

1

I think you mean in the browser environment. No, you can't use Windows API functions in the browser environment (regardless of whether you're writing in JavaScript or one of the languages supported via Wasm), it's a very thoroughly sandboxed environment for security reasons.

For instance, when you have a Discord application installed and you use discord web it prompts you to open in Discord app so most probably it's using the GetProcess Windows library function.

It isn't. On Windows, you can install custom protocol handlers so you can have links with a custom scheme like discord://somethinghere (instead of http://somethinghere). The Discord app does that. It's possible to detect whether a custom protocol has a handler from browser code, and so a web page can tell whether you have the Discord app installed (or more accurately, whether you have a protocol handler installed for the discord: scheme). No Windows API involved (from the JavaScript/TypeScript code side; naturally, the browser is using Windows API under the covers).

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • oh i didnt know that thanks ... do u know if there is anyway we can use systemmediacontrols in javascript or typescript because i was trying to build a vs code extension which uses the systemmediacontrols – ninetynin Oct 15 '22 at 09:15
  • @Anand - I don't know, but I will note that VS Code isn't a browser, although it uses browser technologies, it's an [Electron app](https://www.electronjs.org), which is a combination of Chrome and Node.js. That means you may well be able to use things that you can't use in a browser (at least in the main process that runs in Node.js). – T.J. Crowder Oct 15 '22 at 09:19