I'm using Go to build a DLL.
I'm not able to implement windows DllMain entry point.
My goal is when an app loads the dll via LoadLibrary to call the Test method, the DllMain will be called as well. However currently the app is kind of stuck in deadlock and nothing happens.
The app is quite simple python code
# App code
import ctypes
lib = ctypes.CDLL("./mydll.dll")
lib.Test()
Notes:
I am building using
go version go1.16.4 windows/amd64and building using
go build -o mydll.dll --buildmode=c-sharedIf I remove
DllMain, everything works fine and app can call theTestmethod successfully.I'm aware that I can
switchcase underDllMainto specify conditions such as process attached, detached ...etc, I just wanted to keep it as simple as possible.
//Go Code
package main
import "C"
import (
    "fmt"
    "os"
)
//export Test
func Test() {
    os.Create("fooFile")
}
//export DllMain
func DllMain(a uintptr, b uint32, c uintptr) int32 {
    return 1
}
func main() {
}