forked from ProjectWIND/ProjectWIND
增加main.go中调用dll部分,wind.AppInfo增加了String类WebUrl
This commit is contained in:
parent
5cafc7e5f5
commit
45a24933b0
34
main.go
34
main.go
@ -2,13 +2,47 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"ProjectWIND/core"
|
"ProjectWIND/core"
|
||||||
|
"ProjectWIND/wba"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
var CoreOs = core.GetOS()
|
var CoreOs = core.GetOS()
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// 加载 DLL 文件
|
||||||
|
dll, err := syscall.LoadDLL("wind.dll")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("加载dll文件失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 绑定到 AppInit 函数
|
||||||
|
appInitProc, err := dll.FindProc("AppInit")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("查找AppInit函数失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用 AppInit 函数
|
||||||
|
ret, _, err := appInitProc.Call()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("调用AppInit函数失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理 AppInfo
|
||||||
|
appInfo := (*wba.AppInfo)(unsafe.Pointer(ret)) // 使用导入的 AppInfo
|
||||||
|
|
||||||
|
// 打印 AppInfo 数据
|
||||||
|
fmt.Printf("App Name: %s\n", appInfo.Name)
|
||||||
|
fmt.Printf("Author: %s\n", appInfo.Author)
|
||||||
|
fmt.Printf("Version: %s\n", appInfo.Version)
|
||||||
|
fmt.Printf("Description: %s\n", appInfo.Description)
|
||||||
|
fmt.Printf("Namespace: %s\n", appInfo.Namespace)
|
||||||
|
fmt.Printf("Web URL: %s\n", appInfo.WebUrl)
|
||||||
|
fmt.Printf("License: %s\n", appInfo.License)
|
||||||
|
|
||||||
//如果没有参数,则启动WebUI
|
//如果没有参数,则启动WebUI
|
||||||
if len(os.Args) <= 1 {
|
if len(os.Args) <= 1 {
|
||||||
initCore()
|
initCore()
|
||||||
|
@ -60,6 +60,7 @@ type AppInfo struct {
|
|||||||
License string
|
License string
|
||||||
AppType string
|
AppType string
|
||||||
Rule string
|
Rule string
|
||||||
|
WebUrl string
|
||||||
CmdMap map[string]Cmd
|
CmdMap map[string]Cmd
|
||||||
MessageEventHandler func(msg MessageEventInfo)
|
MessageEventHandler func(msg MessageEventInfo)
|
||||||
NoticeEventHandler func(msg NoticeEventInfo)
|
NoticeEventHandler func(msg NoticeEventInfo)
|
||||||
|
55
wind(dll源文件).go
Normal file
55
wind(dll源文件).go
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"ProjectWIND/wba"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
//export AppInit
|
||||||
|
func AppInit() wba.AppInfo {
|
||||||
|
// 写入应用信息
|
||||||
|
app := wba.NewApp(
|
||||||
|
wba.WithName("app_demo"), // 应用名称
|
||||||
|
wba.WithAuthor("WIND"), // 作者
|
||||||
|
wba.WithVersion("1.0.0"), // 版本
|
||||||
|
wba.WithDescription("This is a demo application"), // 应用描述
|
||||||
|
wba.WithNamespace("app_demo"), // 命名空间, 私有数据库请使用应用的名称, 公共数据库请使用"PUBLIC"
|
||||||
|
wba.WithWebUrl("https://github.com/wind/app_demo"), // 应用主页
|
||||||
|
wba.WithLicense("MIT"), // 应用许可证
|
||||||
|
)
|
||||||
|
|
||||||
|
// 定义命令
|
||||||
|
cmdTest := wba.NewCmd(
|
||||||
|
//命令名称
|
||||||
|
"app",
|
||||||
|
//命令介绍
|
||||||
|
"插件测试",
|
||||||
|
func(args []string, msg wba.MessageEventInfo) {
|
||||||
|
val := args[0]
|
||||||
|
log.Println("app_demo cmdTest", val)
|
||||||
|
switch val {
|
||||||
|
case "help":
|
||||||
|
{
|
||||||
|
wba.Wind.SendMsg(msg, "app_demo help", false)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
wba.Wind.SendMsg(msg, "Hello, wind app!", false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
// 将命令添加到应用命令列表中
|
||||||
|
app.AddCmd("app", cmdTest)
|
||||||
|
|
||||||
|
return app
|
||||||
|
}
|
||||||
|
|
||||||
|
// Application 向核心暴露的应用接口,标识符为Application, 不可修改
|
||||||
|
var Application = AppInit()
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user