1 Star 3 Fork 0

狼浪/go-dmsoft

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
dmsoft.go 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
清风千年 提交于 2020-05-18 19:30 . 小修改dm
// +build windows
// export GOARCH=386
package dmsoft
import (
"syscall"
"unsafe"
ole "github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
)
var (
dmReg32 = syscall.NewLazyDLL("DmReg.dll")
procSetDllPathA = dmReg32.NewProc("SetDllPathA")
procSetDllPathW = dmReg32.NewProc("SetDllPathW")
)
// DmSoft ...
type DmSoft struct {
dm *ole.IDispatch
IUnknown *ole.IUnknown
}
// New return *DmSoft.DmSoft
func New() (dm *DmSoft, err error) {
var com DmSoft
// 创建对象
ole.CoInitialize(0)
com.IUnknown, err = oleutil.CreateObject("dm.dmsoft")
if err != nil {
return nil, err
}
// 查询接口
com.dm, err = com.IUnknown.QueryInterface(ole.IID_IDispatch)
if err != nil {
return nil, err
}
return &com, nil
}
// Release 释放
func (com *DmSoft) Release() {
com.IUnknown.Release()
com.dm.Release()
ole.CoUninitialize()
}
// SetDllPathA Ascii
func SetDllPathA(path string, mode int) bool {
var _p0 *uint16
_p0, _ = syscall.UTF16PtrFromString(path)
ret, _, _ := syscall.Syscall(procSetDllPathA.Addr(), 2, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0)
return ret != 0
}
// SetDllPathW Unicode
func SetDllPathW(path string, mode int) bool {
var _p0 *uint16
_p0, _ = syscall.UTF16PtrFromString(path)
ret, _, _ := syscall.Syscall(procSetDllPathW.Addr(), 2, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0)
return ret != 0
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zphiex/go-dmsoft.git
git@gitee.com:zphiex/go-dmsoft.git
zphiex
go-dmsoft
go-dmsoft
master

搜索帮助