package main

import (
	"C"
	"fmt"
	"net/http"
	_ "net/http/pprof"
	//	"os"
	//	"runtime/pprof"
	"syscall"
	"time"
	"unsafe"
)

var times int

func main() {
	cbStr := syscall.NewCallback(goCbStr)
	dll, error := syscall.LoadDLL("test0001.dll")
	fmt.Println(dll)
	var initConnAgent *syscall.Proc
	initConnAgent, error = dll.FindProc("init")
	fmt.Println(initConnAgent, error)
	initConnAgent.Call(uintptr(unsafe.Pointer(&cbStr)))
	//	f, _ := os.Create("cpu.prof")
	//	err := pprof.StartCPUProfile(f)
	//	if err != nil {
	//		fmt.Println("pprof.StartCPUProfile:", err)
	//	}
	//	defer pprof.StopCPUProfile()
	go func() {
		fmt.Println(http.ListenAndServe("localhost:54321", nil))
	}()
	for {
		time.Sleep(time.Second)
	}
}

func goCbStr(callId int, funtype int, str *C.char) uintptr {
	times++
	fmt.Println(times, callId, funtype, C.GoString(str))
	return uintptr(0)
}
