forked from ying32/govcl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dylib_nonmemory.go
69 lines (58 loc) · 1.45 KB
/
dylib_nonmemory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//----------------------------------------
//
// Copyright © ying32. All Rights Reserved.
//
// Licensed under Apache License 2.0
//
//----------------------------------------
// +build !memorydll
package api
import (
"runtime"
"github.com/ying32/govcl/pkgs/libname"
"github.com/ying32/dylib"
)
var (
platformExtNames = map[string]string{
"windows": ".dll",
"linux": ".so",
"darwin": ".dylib",
}
)
// 加载库
func loadUILib() *dylib.LazyDLL {
libName := "liblcl"
if libname.LibName == "" {
if ext, ok := platformExtNames[runtime.GOOS]; ok {
libName += ext
}
} else {
libName = libname.LibName
}
//fmt.Println("LoadLibrary:", libName)
lib := dylib.NewLazyDLL(libName)
err := lib.Load()
if err != nil {
panic(err)
}
if getLibType(lib) != LtLCL {
// 当前已经不再支持VCL库了。如果有需要,请使用最后一个支持VCL版本的代码:https://github.com/ying32/govcl/tree/last-vcl-support。
panic("The VCL library is no longer supported. If necessary, please use the last code that supports VCL version: https://github.com/ying32/govcl/tree/last-vcl-support.")
}
return lib
}
func getLibType(lib *dylib.LazyDLL) TLibType {
proc := lib.NewProc("DGetLibType")
r, _, _ := proc.Call()
return TLibType(r)
}
// 获取dll库实例,用于在外扩展第三方组件的。移动来自dfuncs.go
func GetLibVcl() *dylib.LazyDLL {
return libvcl
}
func closeLib() {
if libvcl != nil {
libvcl.Close()
libvcl = nil
}
}