Skip to content

Commit

Permalink
fix: 修复linux版无法编译问题
Browse files Browse the repository at this point in the history
  • Loading branch information
rehiy committed Aug 26, 2024
1 parent f57f7d2 commit b9a9f9e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 41 deletions.
41 changes: 0 additions & 41 deletions wcferry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ package wcferry

import (
"errors"
"runtime"
"syscall"
"time"

"github.com/opentdp/go-helper/filer"
"github.com/opentdp/go-helper/logman"
"github.com/opentdp/go-helper/onquit"
)

Expand Down Expand Up @@ -92,40 +88,3 @@ func (c *Client) wxInitSDK() error {
func (c *Client) wxDestroySDK() error {
return c.sdkCall("WxDestroySDK")
}

// 调用 sdk.dll 中的函数
// return error 错误信息
func (c *Client) sdkCall(fn string, a ...uintptr) error {
dll := c.SdkLibrary
if dll == "" || runtime.GOOS != "windows" {
logman.Warn("skip to load sdk.dll")
return nil
}
// 查找 sdk.dll
if !filer.Exists(dll) {
dll = "wcferry/" + dll
if !filer.Exists(dll) {
return errors.New(dll + " not found")
}
}
// 加载 sdk.dll
sdk, err := syscall.LoadDLL(dll)
if err != nil {
logman.Warn("failed to load sdk.dll", "error", err)
return err
}
defer sdk.Release()
// 查找 fn 函数
proc, err := sdk.FindProc(fn)
if err != nil {
logman.Warn("failed to call "+fn, "error", err)
return err
}
// 执行 fn(a...)
r1, r2, err := proc.Call(a...)
logman.Warn("call dll:"+fn, "r1", r1, "r2", r2, "error", err)
if err.Error() == "Attempt to access invalid address." {
err = nil // 忽略已知问题
}
return err
}
14 changes: 14 additions & 0 deletions wcferry/client_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build !windows

package wcferry

import (
"github.com/opentdp/go-helper/logman"
)

// 调用 sdk.dll 中的函数
// return error 错误信息
func (c *Client) sdkCall(fn string, a ...uintptr) error {
logman.Warn("skip to load sdk.dll", "fn", fn, "a", a)
return nil
}
48 changes: 48 additions & 0 deletions wcferry/client_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//go:build windows

package wcferry

import (
"errors"
"syscall"

"github.com/opentdp/go-helper/filer"
"github.com/opentdp/go-helper/logman"
)

// 调用 sdk.dll 中的函数
// return error 错误信息
func (c *Client) sdkCall(fn string, a ...uintptr) error {
if c.SdkLibrary == "" {
logman.Warn("skip to load sdk.dll")
return nil
}
// 查找 sdk.dll
dll := c.SdkLibrary
if !filer.Exists(dll) {
dll = "wcferry/" + dll
if !filer.Exists(dll) {
return errors.New(dll + " not found")
}
}
// 加载 sdk.dll
sdk, err := syscall.LoadDLL(dll)
if err != nil {
logman.Warn("failed to load sdk.dll", "error", err)
return err
}
defer sdk.Release()
// 查找 fn 函数
proc, err := sdk.FindProc(fn)
if err != nil {
logman.Warn("failed to call "+fn, "error", err)
return err
}
// 执行 fn(a...)
r1, r2, err := proc.Call(a...)
logman.Warn("call dll:"+fn, "r1", r1, "r2", r2, "error", err)
if err.Error() == "Attempt to access invalid address." {
err = nil // 忽略已知问题
}
return err
}

0 comments on commit b9a9f9e

Please sign in to comment.