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/amd64
and building using
go build -o mydll.dll --buildmode=c-shared
If I remove
DllMain
, everything works fine and app can call theTest
method successfully.I'm aware that I can
switch
case underDllMain
to 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() {
}