-
Notifications
You must be signed in to change notification settings - Fork 44
/
dmsoft.go
58 lines (50 loc) · 1.16 KB
/
dmsoft.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
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")
_SetDllPathA = dmReg32.NewProc("SetDllPathA")
_SetDllPathW = dmReg32.NewProc("SetDllPathW")
)
type Dmsoft struct {
dm *ole.IDispatch
IUnknown *ole.IUnknown
}
func NewDmsoft() *Dmsoft {
var com Dmsoft
var err error
ole.CoInitialize(0)
com.IUnknown, err = oleutil.CreateObject("dm.dmsoft")
if err != nil {
panic(err)
}
com.dm, err = com.IUnknown.QueryInterface(ole.IID_IDispatch)
if err != nil {
panic(err)
}
return &com
}
// 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, _, _ := _SetDllPathA.Call(uintptr(unsafe.Pointer(_p0)), uintptr(mode))
return ret != 0
}
// SetDllPathW Unicode
func SetDllPathW(path string, mode int) bool {
var _p0 *uint16
_p0, _ = syscall.UTF16PtrFromString(path)
ret, _, _ := _SetDllPathW.Call(uintptr(unsafe.Pointer(_p0)), uintptr(mode))
return ret != 0
}