Giter Club home page Giter Club logo

deno_win32's Introduction

Deno Win32

Tags Checks License Sponsor

Fast and complete Win32 API bindings for Deno using FFI.

Example

import {
  MB_OKCANCEL,
  MessageBoxA,
} from "https://win32.deno.dev/0.4.1/UI.WindowsAndMessaging";

const result = MessageBoxA(
  null,
  "Hello, world!",
  "Hello",
  MB_OKCANCEL,
); // 1 (OK) or 2 (Cancel)

More in examples/ such as demonstrating OpenGL API usage.

Usage

You need to pass --allow-ffi and --unstable flags in order to access the Win32 API.

deno run --allow-ffi --unstable <file>

Note: It is highly recommended to import only APIs you need. Do not import from mod.ts as it will import all sub modules which you might not even need. WinAPI is huge, so are the bindings.

Documentation

It is recommened to read the official documentation of Win32 API.

APIs almost map 1:1 with the official ones, just certain types have to be transformed to be sent into C-land like string is first converted into null-terminated string depending on the argument (PSTR or PWSTR).

Constants are exported as-is. Structs are defined as interfaces with corresponding JS types in fields. We also export a helper function alloc${STRUCT} which accepts Partial<${STRUCT}> to create a new struct and return its buffer as Uint8Array. A constant called sizeof${camelCasedStruct} is exported which is the size of the struct in bytes.

Some APIs have been (manually) marked as Async capable which adds a ${name}Async variant of the function along with original one which runs on a different thread natively and returns a promise. If you want any other API to be Async capable, please open an issue or a PR. Note that Async calls cannot go through v8 fastapi path, so they have more overhead than normal ones.

Contributing

Code is formatted using deno fmt and linted using deno lint. Please make sure to run these commands before committing.

License

Apache-2.0. Check LICENSE for more details.

Copyright 2022-2023 © DjDeveloperr

deno_win32's People

Contributors

djdeveloperr avatar

Stargazers

 avatar Ángel Gómez avatar Chance Snow avatar Christian Gewert avatar Jari Pennanen avatar Julian Blazek avatar Horace Lee avatar Regan avatar Koji Hisano avatar AnQi avatar  avatar  avatar Mohammed avatar Pavel Udaloff avatar Davi Rafael avatar Mohsen Khanpour avatar Abdullah Atta avatar Sandalots avatar Syntax avatar Ammar Ahmed avatar Jamie Birch avatar максим лисица avatar Matheus Vargem avatar  avatar  avatar Keritial avatar Yoshihiro Ueki avatar Andy Lu avatar Hank Bao avatar 迷渡 avatar Tom avatar hashrock avatar Sabbir Ahmed avatar Santhosh Veer avatar wangb avatar  avatar Marc Espin avatar Divy Srivastava avatar  avatar Dean Srebnik avatar Ciro Lo Sapio avatar Nassim Zen avatar Elias Sjögreen avatar

Watchers

ud2 avatar  avatar  avatar

deno_win32's Issues

[Closed]Please help me check, for System.Threading, why can't I use online files, but only local files?

console.log('Begin:', new Date());

// ok
import { Sleep as sleep_ok } from "../api/System/Threading.ts";
try {
sleep_ok(1000);
console.log('sleep_ok', new Date());
} catch(e) {
console.error(e);
}

import { Sleep as sleep_0_4_1} from "https://win32.deno.dev/0.4.1/System.Threading";
try {
sleep_0_4_1(1000);
console.log('sleep_0_4_1', new Date());
} catch(e) {
console.error(e);
}

import { Sleep as sleep_0_4_0} from "https://win32.deno.dev/0.4.0/System.Threading";
try {
sleep_0_4_0(1000);
console.log('sleep_0_4_0', new Date());
} catch(e) {
console.error(e);
}

import { Sleep as sleep_0_2_0} from "https://win32.deno.dev/0.2.0/System.Threading";
try {
sleep_0_2_0(1000);
console.log('sleep_0_2_0', new Date());
} catch(e) {
console.error(e);
}

console.log('End:', new Date());

/*
Begin: 2024-01-05T23:55:59.831Z
sleep_ok 2024-01-05T23:56:00.836Z
TypeError: Cannot read properties of undefined (reading 'Sleep')
at Sleep (https://win32.deno.dev/0.4.1/System.Threading:9883:26)
at file:///P:/anqi/Desktop/tech/deno/projects/deno_win32-main/anqi/threading.ts:24:5
TypeError: Cannot read properties of undefined (reading 'Sleep')
at Sleep (https://win32.deno.dev/0.4.0/System.Threading:9883:26)
at file:///P:/anqi/Desktop/tech/deno/projects/deno_win32-main/anqi/threading.ts:32:5
TypeError: Cannot read properties of undefined (reading 'Sleep')
at Sleep (https://win32.deno.dev/0.2.0/System.Threading:6940:26)
at file:///P:/anqi/Desktop/tech/deno/projects/deno_win32-main/anqi/threading.ts:40:5
End: 2024-01-05T23:56:00.867Z
*/

How to hide/mimize console

Deno has an compile option --no-terminal (which should work on win, but it doesn't).

github isue #21091

So i tried :

import { GetConsoleWindow } from 'https://win32.deno.dev/0.4.1/System.Console';
import {
   SW_HIDE,
   ShowWindow,
} from 'https://win32.deno.dev/0.4.1/UI.WindowsAndMessaging';

function hideConsole() {
   ShowWindow(GetConsoleWindow(), SW_HIDE);
}

console.log('before');
setInterval(() => console.log('after'), 5000);

hideConsole();

Console is still open.

`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.