增加main.go中调用dll部分,wind.AppInfo增加了String类WebUrl

This commit is contained in:
Forest 2025-02-20 22:13:01 +08:00
parent 5cafc7e5f5
commit 45a24933b0
3 changed files with 90 additions and 0 deletions

34
main.go
View File

@ -2,13 +2,47 @@ package main
import (
"ProjectWIND/core"
"ProjectWIND/wba"
"fmt"
"log"
"os"
"syscall"
"unsafe"
)
var CoreOs = core.GetOS()
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
if len(os.Args) <= 1 {
initCore()

View File

@ -60,6 +60,7 @@ type AppInfo struct {
License string
AppType string
Rule string
WebUrl string
CmdMap map[string]Cmd
MessageEventHandler func(msg MessageEventInfo)
NoticeEventHandler func(msg NoticeEventInfo)

55
wind(dll源文件).go Normal file
View 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() {
}