Skip to content

Commit

Permalink
U: 增加SetReleaseCallback 应用运行结束后释放资源之前执行
Browse files Browse the repository at this point in the history
  • Loading branch information
sxmxta committed Dec 28, 2023
1 parent 3a44ff6 commit e311459
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lcl/api/dllimports/importfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func internalGetImportFunc(uiLib DLL, table []*ImportTable, index int) ProcAddr
var err error
item.addr, err = uiLib.GetProcAddr(item.name)
if err != nil {
fmt.Println(err)
fmt.Println(err, item.name)
return 0
}
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&table[index].addr)), unsafe.Pointer(item.addr))
Expand Down
12 changes: 12 additions & 0 deletions lcl/api/energy_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ package api

import "github.com/energye/golcl/lcl/api/dllimports"

var releaseCallback func()

func APIInit() {
uiLib = loadUILib()
}
Expand All @@ -25,6 +27,16 @@ func ImportDefFunc(importTable []*dllimports.ImportTable, index int) dllimports.

// EnergyLibRelease 在energy中释放
func EnergyLibRelease() {
if releaseCallback != nil {
releaseCallback()
}
callGC()
closeLib()
}

// SetReleaseCallback 应用运行结束后释放资源之前执行
func SetReleaseCallback(fn func()) {
if releaseCallback == nil {
releaseCallback = fn
}
}
3 changes: 3 additions & 0 deletions lcl/api/importdef.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func Application_CreateForm(app uintptr) uintptr {

func Application_Run(app uintptr) {
defer func() {
if releaseCallback != nil {
releaseCallback()
}
// 开启了finalizerOn选项后,以防止关闭库后GC还没开始调用。
callGC()
// 运行结束后就结束close掉lib,不然他不会关掉的
Expand Down

0 comments on commit e311459

Please sign in to comment.