~eliasnaur/gio-patches

gio: Add support for Windows DebugView logging v1 PROPOSED

~typeless
Windows GUI programs close all stdin/stdout/stderr by default.
This
patch adds the native logging support provided by Windows.

mural (1):
  app/internal/log: add logger for Windows DbgView

 app/internal/log/log_windows.go | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 app/internal/log/log_windows.go

-- 
2.24.1
Thank you. Can you say something about where the debugging output end
up (I don't have much Windows development experience)? How will the
change affect programs that are not built with `-H windowsgui`?
On Thu Jan 9, 2020 at 3:43 PM, ~typeless wrote:
Next
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~eliasnaur/gio-patches/patches/9481/mbox | git am -3
Learn more about email & git

[PATCH gio 1/1] app/internal/log: add logger for Windows DbgView Export this patch

~typeless
From: mural <mural@ctli.io>

---
 app/internal/log/log_windows.go | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 app/internal/log/log_windows.go

diff --git a/app/internal/log/log_windows.go b/app/internal/log/log_windows.go
new file mode 100644
index 0000000..0587fc9
--- /dev/null
+++ b/app/internal/log/log_windows.go
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: Unlicense OR MIT

// +build windows

package log

import (
	"log"
	"syscall"
	"unsafe"
)

type logger struct{}

var kernel32 = syscall.NewLazyDLL("kernel32")
var outputDebugStringW = kernel32.NewProc("OutputDebugStringW")
var out logger

func init() {
	// Windows DbgView already includes timestamps.
	log.SetFlags(log.Flags() &^ log.LstdFlags)
	log.SetOutput(&out)
}

func (l *logger) Write(buf []byte) (int, error) {
	p, err := syscall.UTF16PtrFromString(string(buf))
	if err != nil {
		return 0, err
	}
	outputDebugStringW.Call(uintptr(unsafe.Pointer(p)))
	return len(buf), nil
}
-- 
2.24.1
Thank you. Can you say something about where the debugging output end
up (I don't have much Windows development experience)? How will the
change affect programs that are not built with `-H windowsgui`?

On Thu Jan 9, 2020 at 3:43 PM, ~typeless wrote:
View this thread in the archives