FAQ
Package winq provides functions for quick & dirty WinAPI calls, with easy
errors capturing.

This is a somewhat low-level and "unsafe" library, aimed at helping and
easing the job for people writing more "high level" WinAPI/GUI libraries,
or for people experimenting with WinAPI regions not-yet-covered by prettier
libs, or those just wanting to do things oldschool-ish on their own terms.

Features/pros:
- automatic casting of arguments to uintptr,
- very short notation ("amortized one-line"),
- easy and convenient errors capturing and checking (N = Nonzero is ok; Z =
Zero is ok; A = Anything is ok; X = eXtra handling required),
- in case of error, subsequent calls are not executed, so multiple calls
can be "chained" in sequence, and error handling code inserted only
sparingly,
- special purpose "defer" pattern for resources deallocation - full example
below:

var try winq.Try

dc := try.N("BeginPaint", hwnd, &paintstruct)
defer try.Detach().N("EndPaint", hwnd, &paintstruct)
memdc := try.N("CreateCompatibleDC", dc) // if this fails, above EndPaint will still run
defer try.Detach().N("DeleteDC", memdc)
if try.Err != nil {
  return try.Err
}


- MIT/BSD/public-domain licensed open-source code - get at:
https://github.com/akavel/winq
- documentation at: http://godoc.org/github.com/akavel/winq
- list of supported DLLs can be easily extended via append(winq.DLLs, ...),
- no need to worry whether it's BeginPaint or BeginPaintW,
- functions are loaded lazily on first call, but then cached in thread-safe
manner,
- I took care to try and implement the calls in garbage-collector-safe way,
although I'm not a core Go dev, so I'm not qualified and knowledgeable
enough to guarantee anything here,
- I strove to build it as a small but powerful, focused, one-purpose
library.

IMPORTANT: "Unfeatures"/limitations/cons:
- no typechecking of arguments!!! - you're at similar risk as when using
package "unsafe", and you still have to consult MSDN on every step;
- you still have to consult MSDN to know what every called function
returns, and what it means;
- functions are checked and loaded only lazily on first call - so you won't
learn quickly about any misspellings, and they are hardwired to panic on
load failure (so that you could still learn about them at some point);
- the package adds A Level Of Indirection so any Super Fast Code could run
Slightly Slower if it depends on speed of WinAPI calls - although I'd
suggest to measure first, and optimize only afterwards; also, WinAPI calls
are already somewhat heavyweight in Go, and still your every fmt.Println
does use them AFAIK;
- each call issues one tiny read-lock inside - but see point above about
Super Fast Code vs. WinAPI;
- list of searched DLLs is exposed in the package, so there's some risk
some user could try to remove from it [TODO: drop this possibility in
future v2 API].

import "github.com/akavel/winq"
code: https://github.com/akavel/winq
docs: http://godoc.org/github.com/akavel/winq
license: MIT/BSD/public-domain at your discretion.

Hope you find it useful.
/Mateusz Czapliński.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 10, '14 at 6:49p
activeSep 10, '14 at 6:49p
posts1
users1
websitegolang.org

1 user in discussion

Mateusz Czapliński: 1 post

People

Translate

site design / logo © 2022 Grokbase