Calling golang dll library in golang (windows)

How to use a golang library (dll) in golang projects with newlazydll? (windows)

fatal error: unexpected signal during runtime execution
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x623d43dd]


It is a bit hard for us to understand why this happens if you don’t give us more information. What did you want to do? What steps did you take to get there? Any code you used. So try to be more specific if you can and the possibility of getting help will increase.

With regards, Johan


package main

import "C"

//export s
func s() string {
	return "HELLO"

func main() {
	// Need a main function to make CGO compile package as C shared library

Project with call PrintBye:

package main

import "C"

import (




func main() {

var mod = syscall.NewLazyDLL("dll.dll")

var proc = mod.NewProc("PrintBye")

ret, _, _ := proc.Call()

fmt.Printf("Return: %d\n", ret)


Build dll: go build -o dll.dll -buildmode=c-shared dll.go
Build exe: go build project.go

fatal error: unexpected signal during runtime execution
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x623d43dd]

goroutine 1 [running]:
runtime.throw(0x624c3b48, 0x2a)
	C:/Go/src/runtime/panic.go:608 +0x79 fp=0xc000071718 sp=0xc0000716e8 pc=0x623eb1b9
	C:/Go/src/runtime/signal_windows.go:198 +0x16f fp=0xc000071748 sp=0xc000071718 pc=0x623fd6df
runtime.heapBitsSetType(0xc0000421c0, 0x10, 0x10, 0x62497600)
	C:/Go/src/runtime/mbitmap.go:982 +0x9bd fp=0xc000071850 sp=0xc000071748 pc=0x623d43dd
runtime.mallocgc(0x10, 0x62497600, 0x1c000048001, 0x40)
	C:/Go/src/runtime/malloc.go:933 +0x57f fp=0xc0000718f0 sp=0xc000071850 pc=0x623cbf4f
runtime.convT2Estring(0x62497600, 0xc000071978, 0x40, 0x624d4500)
	C:/Go/src/runtime/iface.go:343 +0x6f fp=0xc000071920 sp=0xc0000718f0 pc=0x623c9c8f
	C:/Go/src/runtime/panic.go:421 +0xec fp=0xc000071998 sp=0xc000071920 pc=0x623ea8fc
panic(0x624a0020, 0x6247ed50)
	C:/Go/src/runtime/panic.go:554 +0x2c7 fp=0xc000071a28 sp=0xc000071998 pc=0x623eadd7
	C:/Go/src/runtime/panic.go:82 +0x65 fp=0xc000071a48 sp=0xc000071a28 pc=0x623e9dd5
	C:/Go/src/runtime/signal_windows.go:204 +0x81 fp=0xc000071a78 sp=0xc000071a48 pc=0x623fd5f1
os.(*File).write(0x0, 0xc00004c0a0, 0x7, 0x8, 0x0, 0x1c000042080, 0x1c0000420a8)
	C:/Go/src/os/file_windows.go:224 +0x29 fp=0xc000071ac0 sp=0xc000071a78 pc=0x62440339
os.(*File).Write(0x0, 0xc00004c0a0, 0x7, 0x8, 0x5813b0, 0x3c4000, 0x40b4d9)
	C:/Go/src/os/file.go:145 +0x70 fp=0xc000071b30 sp=0xc000071ac0 pc=0x6243f030
fmt.Fprintln(0x624d4420, 0x0, 0xc000071c18, 0x1, 0x1, 0xc000071cb0, 0x2e06a0, 0x0)
	C:/Go/src/fmt/print.go:255 +0x92 fp=0xc000071b98 sp=0xc000071b30 pc=0x6245dd12
fmt.Println(0xc000071c18, 0x1, 0x1, 0x43b68e, 0x10, 0xc000002180)
	C:/Go/src/fmt/print.go:264 +0x5e fp=0xc000071be8 sp=0xc000071b98 pc=0x6245ddde
	C:/Users/Cat/Desktop/Projects/DLL/dll.go:9 +0x68 fp=0xc000071c58 sp=0xc000071be8 pc=0x6246e668
	_cgo_gotypes.go:45 +0x27 fp=0xc000071c68 sp=0xc000071c58 pc=0x6246e5e7
runtime.call32(0x0, 0x22fb70, 0x22fcef, 0x0)
	C:/Go/src/runtime/asm_amd64.s:522 +0x42 fp=0xc000071c98 sp=0xc000071c68 pc=0x62412c12
	C:/Go/src/runtime/cgocall.go:316 +0x1a9 fp=0xc000071d10 sp=0xc000071c98 pc=0x623c46c9
	C:/Go/src/runtime/cgocall.go:194 +0xeb fp=0xc000071d78 sp=0xc000071d10 pc=0x623c447b
runtime: unexpected return pc for runtime.cgocallback_gofunc called from 0x4515f7
stack: frame={sp:0xc000071d78, fp:0xc000071d98} stack=[0xc00006a000,0xc000072000)
000000c000071c78:  0000000002030000  000000c000071ca0 
000000c000071c88:  000000c000071d00  00000000623c46c9 <runtime.cgocallbackg1+425> 
000000c000071c98:  0000000000000000  000000000022fb70 
000000c000071ca8:  000000000022fcef  0000000000000000 
000000c000071cb8:  000ffaaaabfeaaaa  000000c000071d00 
000000c000071cc8:  000000c000071d08  000000c000071d00 
000000c000071cd8:  01000000623f4096  000000c000002180 
000000c000071ce8:  0000000200000003  000000c000002180 
000000c000071cf8:  000000c000002180  000000c000071d68 
000000c000071d08:  00000000623c447b <runtime.cgocallbackg+235>  0000000000000000 
000000c000071d18:  0000000000000020  0000000000403ba5 
000000c000071d28:  00000000623c14e0  0000000000000000 
000000c000071d38:  000000c000071e18  00000000623c14e0 
000000c000071d48:  0000000000000000  0000000000000000 
000000c000071d58:  000000c000071da0  000000c000002180 
000000c000071d68:  000000000022fb30  0000000062414272 <runtime.cgocallback_gofunc+178> 
000000c000071d78: <0000000000000000  00000000005663c0 
000000c000071d88:  000000c000071da0 !00000000004515f7 
000000c000071d98: >0000000000403bc9  0000000000453700 
000000c000071da8:  0000000000566688  000000c0000400f0 
000000c000071db8:  000000c000046440  00000000005663c0 
000000c000071dc8:  000000c000071df8  0000000000443679 
000000c000071dd8:  0000000000453700  0000000000566688 
000000c000071de8:  00000000623c14e0  00000000005663c0 
000000c000071df8:  000000c000071ed0  000000000045b1f0 
000000c000071e08:  00000000623c14e0  0000000000000000 
000000c000071e18:  0000000000000000  0000000000000000 
000000c000071e28:  0000000000000000  0000000000000000 
000000c000071e38:  0000000000000000  0000000000000000 
000000c000071e48:  0000000000403aa7  00000000004e0b28 
000000c000071e58:  000000c000046440  000000c000071e78 
000000c000071e68:  000000c000071ea8  000000000045c4b9 
000000c000071e78:  000000c000060240  000000c000046440 
000000c000071e88:  0000000000000008  000000c000046440 
runtime.cgocallback_gofunc(0x403bc9, 0x453700, 0x566688, 0xc0000400f0)
	C:/Go/src/runtime/asm_amd64.s:775 +0xb2 fp=0xc000071d98 sp=0xc000071d78 pc=0x62414272

goroutine 1 [runnable, locked to thread]:
syscall.SetHandleInformation(0x2b4, 0x1, 0x0, 0x30)
	C:/Go/src/syscall/zsyscall_windows.go:954 +0xe3
	C:/Go/src/syscall/exec_windows.go:125 +0x3b
syscall.getStdHandle(0xfffffffffffffff6, 0x624bf2aa)
	C:/Go/src/syscall/syscall_windows.go:387 +0x45

Hi again

The first program dll.go is almost entirely similar to the second program project.go. Did you paste the wrong source code for the dll.go program? One tip also: if you want your go code to be nicely formated paste it between two lines ```go and ``` in the edit box (the three characters are backticks)

package main

import "C"

//export PrintBye
func PrintBye() string {
	return "HELLO"

func main() {
	// Need a main function to make CGO compile package as C shared library


I tested and I get the same result. I tried stepping thru it with the debugger and it fails deep down in syscall then actually calling this:

ptr := proc.Addr()
r1, r2, err := syscall.Syscall(ptr, 0, 0, 0, 0)

I don’t think I can give you any more help. I guess you did this as an experiment. If you want to really use dynamic libraries in go written in go you can use a new module system instead see:

Currently plugins are only supported on Linux and macOS.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.