Skip to content

Commit

Permalink
U: dylib, add SetLoadUILibCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
sxmxta committed Jul 19, 2023
1 parent 59a81a3 commit b64658d
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions lcl/api/dylib.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,29 @@ import (
)

var (
// 全局导入库
uiLib dllimports.DLL
uiLib dllimports.DLL // 全局导入库
loadUILibCallback func() (path string, ok bool) // 自定义加载liblcl动态库回调函数
)

// SetLoadUILibCallback
// 设置加载liblcl动态库回调函数
// 如果设置该回调函数我们可以自定义加载动态链接库
// 在调用 inits.Init 之前设置
func SetLoadUILibCallback(fn func() (path string, ok bool)) {
if loadUILibCallback == nil {
loadUILibCallback = fn
}
}

func loadUILib() dllimports.DLL {
libName := libname.LibName
var libName string
if loadUILibCallback != nil {
if path, ok := loadUILibCallback(); ok {
libName = path
}
} else {
libName = libname.LibName
}
lib, err := dllimports.NewDLL(libName)
if err != nil {
panic(err)
Expand All @@ -38,10 +55,6 @@ func closeLib() {
}
}

func getDLLName() string {
return libname.GetDLLName()
}

// 调用自动生成的API列表中的函数
func syscallN(trap int, args ...uintptr) uintptr {
r1, _, _ := dllimports.GetImportFunc(uiLib, trap).Call(args...)
Expand Down

0 comments on commit b64658d

Please sign in to comment.