How to reference a COM type library (interop) in a VS Code extension? - com

I'd like to develop a VS Code extension that consumes a COM type library (interop) of a third-party application?
Ideally, I'd like to write the extension in F# (Fsharp) using Fable to compile it to JS, but that's not totally essential. In any case, I can reference and use the COM library from F#, C# and VB.NET and provide a .NET library as a wrapper if needed.
Context: I'm new to VS Code extension development. I managed to compile a hello world extension in JavaScript and in F#+Fable. What I probably don't understand is how to use the package.json file and the npm package manager to reference the library.
Edit: I tried the node.js library winax, but without success. Is there an alternative?

A colleague managed to get Winax (Node.js addon) working within the VS Code extension. It's important to recompile winax against the same version of Node.js and Electron that are used in the current version VS Code. (At the time of writing, VS Code 1.16.0 uses Node.js 7.4.0 and Electron 1.7.3.)
In the command line (in your extension project folder) do
npm install --save winax
cd node_modules\winax
node-gyp configure
node-gyp build
cd ..\..
npm rebuild winax --runtime=electron --target=1.7.3 --disturl=https://atom.io/download/atom-shell --build-from-source
The Electron version may need updating in --target=1.7.3.
Now use Winax in the VS Code extension for instance like this
var winax = require('winax');
var excel = new winax.Object("Excel.Application");
excel.visible = true;
Works like a charm for me =)

The approach is relatively simple. You have to write a native node module. This module is a C++ DLL which you can use to import the typelib for the COM library you want to use. It also can provide an access layer that translates calls from V8 to that COM lib.

Related

Using NPM packages with Rust and Webassembly

Is there a way to use npm packages inside Rust code along with webassembly? Right now using webpack, #wasm-tool/wasm-pack-plugin and wasm_bindgen crate that were already present in this template: https://github.com/rustwasm/rust-webpack-template/tree/master/template
TIA.
Is there a way to use npm packages inside Rust code along with webassembly?
No, with Rust you use crates from https://crates.io/ instead. Your Rust code including its dependencies (the crates) will be compiled to binary webassembly.

What is the best way to use SASS inside a Blazor Web Assembly project?

What is the best way to use SASS with Client side blazor. I looked into the this
https://github.com/madskristensen/WebCompiler
But it looks like works only with Visual Studio. I am using Visual Studio Code.
As mentioned in the MS docs, you can use the Delegate.SassBuilder package to help you compile sass/scss files to css.
It works pretty well, and very easy to install with no configuration required.
NOTE
For newer Sass build requirements - I've created this LibSassBuilder
I recommend using sass directly from the command line.* Note that:
Dart Sass is the primary implementation of Sass
and it can be installed and used globally as a CLI tool, no npm project or pipeline required is the key.
You can install sass via choco:
choco install sass
Or with with npm:
npm install -g sass
Then you can right click on wwwroot and select Open in terminal and build and watch in native ways enabled by sass. To watch all see the following for instance:
sass --watch .:.
(A bit begrudgingly, but other solutions, like building on every build, has big downsides. Like it building sass resources on every build: That's really wasteful when you've not been messing with your styles ... Or take the fact, in my case right now, that neither the WebCompiler extension nor LibSassBuilder as mentioned above seem to work on this preview version of Visual Studio.)

Kotlin Native libcurl example on Windows

I'm trying to learn how Kotlin Native works with this tutorial from JetBrains: https://kotlinlang.org/docs/tutorials/native/interop-with-c.html
But these tutorials are only fro macOS and Linux. Sometimes i use a windows computer and i want to know how it works there.
How can i add the libcurl library in windows and how can i add it to the libcurl.def file?
It isn't explained anywhere.
You need to install MSYS2, then in MSYS2 console install libcurl:
$ pacman -S mingw-w64-x86_64-curl
See https://github.com/JetBrains/kotlin-native/pull/1499
A more detailed step-by-step explanation on how to use dynamically built libcurl (aka DLL) with Kotlin/Native.
https://jonnyzzz.com/blog/2018/10/29/kn-libcurl-windows/
I do not think it is covered somewhere right now. The idea is still the same, and you should be able to make it work. The first step is to download and build libcurl locally from https://curl.haxx.se/libcurl/. There are instructions and documentation on how to build it. I do recommend to pick the Windows own implementation for SSL.
Once you are done with building you will have both the includes and the library. Note, on Windows, you will always have a static library. Even if you build curl as a dynamic library (DLL), you will have a generated static library that you use for linking. DLL is easier to build and use. A true static library is better because you will have no dependencies in your Kotlin/Native program binary. At that point, the tutorial instructions should work.
For Windows, if you need only basic HTTP communication, you can also try WinINet API which is a part of Windows and so no dependency is necessary. No hassle with the libcurl library.
See my example of how to use WinInet API with Kotlin MPP: https://github.com/localazy/kotlin-mpp-wininet
For macOS and Linux, instead of going through the hassle with libcurl manually, just use ktor clients: https://ktor.io/clients/index.html
I'm studying Kotlin too and it took many hours until I realize how to handle def file, includes and static library.
I made an example of how to use static library (curl with gzip and SSL support compiled with mingw) on kotlin-native. This way you dont need to dll files to be supplied with your app
https://github.com/carlosrafp/Libcurl-Kotlin-Native-standalone
On libcurl.def file you can see:
headers = curl/curl.h // path to curl header
libraryPaths = src/nativeInterop/cinterop // path to your static library
staticLibraries = libcurl.a // the static library
linkerOpts.mingw = -lws2_32 -lwldap32 // linking dependences
I based on the nice post of jonnyzzz:
https://jonnyzzz.com/blog/2018/10/29/kn-libcurl-windows/

node-express app.get() marked as unresolved in webstorm

If you follow JetBrains' Getting Started with Node.js in WebStorm instructions, node-express specific code is highlighted correctly. However if you create your own simple node-express project, e.g. using node-express' Guide, then express specific functions such as app.get() are underlined and marked with the following warning:
Unresolved function or method get()
This happens even if you enable the following libraries under Settings\JavaScript\Libraries:
Node.js Globals
Node.js v0.10.31 Core Modules
express-DefinitelyTyped (which you need to download)
How can I configure WebStorm to resolve node-express functions such as app.get()?
Instead of express definitelyTyped, use express types in your project:
npm install --save-dev #types/express
Alternatively, for yarn users:
yarn add --dev #types/express
This worked great for me.
TL;DR:
you go to Settings/Preferences --> Languages and Frameworks --> JavaScript --> Libraries, click the Download button on the right, then select "express" (or any other library you need) and click Download and Install.
Enabling express-DefinitelyTyped typescript library for Express project does work for me - app.get() is successfully resolved. Adding typescript stubs is the only possible workaround, as WebStorm can't understand the way express is defined - see https://youtrack.jetbrains.com/issue/WEB-6667#comment=27-470393
If adding typescript stubs doesn't work for you, please try invalidating caches. If this doesn't help, I'd suggest contacting jetbrains support, providing a sample project

How to build gstreamer-sharp with monodevelop/xamarin?

i'm developer of AudioCuesheetEditor, an application for editing audio cuesheets. The new Version should be able to play back sound, so I would like to use gstreamer as backend. I investigated a bit in gstreamer and found out, that I need to use version 1.x with gstreamer-sharp 0.99.x binding. No problem, downloaded gstreamer-sharp 0.99.0, opened the solution with monodevelop (on linux) or xamarin (on windows) and tried to build the dll, but that didn't work. I get the error "namespace Gst.GLib" not found.
I'm developing with xamarin/monodevelop and need to have a portable app (working with mono/.net).
Can anyone help me, get gstreamer-sharp build?
Thanks in advance!
gstreamer-sharp is currently not supported on Windows, however you can compile the managed parts on linux and compile the glue on Windows using Visual Studio:
Install gtk-sharp 3.0 from https://github.com/mono/gtk-sharp
Compile gstreamer-sharp using ./autogen.sh && make
Take the compiled glib-sharp and gstreamer-sharp binary and all .c files from sources/glue/
Download and install gstreamer binaries from http://gstreamer.freedesktop.org/data/pkg/windows/1.2.2/ and install the development and binary packages for the architecture you want to compile for. You can use gstreamer 1.0 or 1.2.
Use the Visual Studio template from the gstreamer-devel package and change the project type to library. Add the c files taken from the sources/glue folder and compile the glue library. The library should be called libgstreamersharpglue-1.0.0.dll
Put the managed parts together with the native symbols.
EDIT:
Compiling the glue is now easier on Windows! Someone set up a project which can compile the glue using Visual Studio on Windows. I have a fork which has binaries at https://github.com/xDarkice/libgstreamersharpglue
gstreamer-sharp uses autotools for its build system, you cannot build it with an IDE. Please do the autotools dance:
./autogen.sh --prefix=/the/prefix/where/you/want/to/install
make
sudo make install