Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

Commit

Permalink
deleted depricated method for string, now use UTF16PtrFromString
Browse files Browse the repository at this point in the history
  • Loading branch information
ergoz committed Aug 10, 2019
1 parent 8fb80e0 commit d165716
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 59 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
.idea/workspace.xml
.idea/libraries/Go_SDK.xml
.idea/vcs.xml
.idea/libraries/GOPATH__w32_.xml
.idea/w32.iml
.idea/modules.xml
.idea
56 changes: 28 additions & 28 deletions advapi32.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func ControlTrace(hTrace TRACEHANDLE, lpSessionName string, props *EVENT_TRACE_P

ret, _, _ := procControlTrace.Call(
uintptr(unsafe.Pointer(hTrace)),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpSessionName))),
uintptr(pointerStringWithoutError(lpSessionName)),
uintptr(unsafe.Pointer(props)),
uintptr(dwControl))

Expand All @@ -88,7 +88,7 @@ func StartTrace(lpSessionName string, props *EVENT_TRACE_PROPERTIES) (hTrace TRA

ret, _, _ := procStartTrace.Call(
uintptr(unsafe.Pointer(&hTrace)),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpSessionName))),
uintptr(pointerStringWithoutError(lpSessionName)),
uintptr(unsafe.Pointer(props)))

if ret == ERROR_SUCCESS {
Expand Down Expand Up @@ -119,7 +119,7 @@ func RegCreateKey(hKey HKEY, subKey string) HKEY {
var result HKEY
ret, _, _ := procRegCreateKeyEx.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))),
uintptr(pointerStringWithoutError(subKey)),
uintptr(0),
uintptr(0),
uintptr(0),
Expand All @@ -135,7 +135,7 @@ func RegOpenKeyEx(hKey HKEY, subKey string, samDesired uint32) HKEY {
var result HKEY
ret, _, _ := procRegOpenKeyEx.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))),
uintptr(pointerStringWithoutError(subKey)),
uintptr(0),
uintptr(samDesired),
uintptr(unsafe.Pointer(&result)))
Expand All @@ -161,11 +161,11 @@ func RegGetRaw(hKey HKEY, subKey string, value string) []byte {
var bufLen uint32
var valptr unsafe.Pointer
if len(value) > 0 {
valptr = unsafe.Pointer(syscall.StringToUTF16Ptr(value))
valptr = pointerStringWithoutError(value)
}
procRegGetValue.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))),
uintptr(pointerStringWithoutError(subKey)),
uintptr(valptr),
uintptr(RRF_RT_ANY),
0,
Expand All @@ -179,7 +179,7 @@ func RegGetRaw(hKey HKEY, subKey string, value string) []byte {
buf := make([]byte, bufLen)
ret, _, _ := procRegGetValue.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))),
uintptr(pointerStringWithoutError(subKey)),
uintptr(valptr),
uintptr(RRF_RT_ANY),
0,
Expand All @@ -196,7 +196,7 @@ func RegGetRaw(hKey HKEY, subKey string, value string) []byte {
func RegSetBinary(hKey HKEY, subKey string, value []byte) (errno int) {
var lptr, vptr unsafe.Pointer
if len(subKey) > 0 {
lptr = unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))
lptr = pointerStringWithoutError(subKey)
}
if len(value) > 0 {
vptr = unsafe.Pointer(&value[0])
Expand All @@ -215,7 +215,7 @@ func RegSetBinary(hKey HKEY, subKey string, value []byte) (errno int) {
func RegSetString(hKey HKEY, subKey string, value string) (errno int) {
var lptr, vptr unsafe.Pointer
if len(subKey) > 0 {
lptr = unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))
lptr = pointerStringWithoutError(subKey)
}
var buf []uint16
if len(value) > 0 {
Expand All @@ -239,7 +239,7 @@ func RegSetString(hKey HKEY, subKey string, value string) (errno int) {
func RegSetUint32(hKey HKEY, subKey string, value uint32) (errno int) {
var lptr unsafe.Pointer
if len(subKey) > 0 {
lptr = unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))
lptr = pointerStringWithoutError(subKey)
}
vptr := unsafe.Pointer(&value)
ret, _, _ := procRegSetValueEx.Call(
Expand All @@ -257,8 +257,8 @@ func RegGetString(hKey HKEY, subKey string, value string) string {
var bufLen uint32
procRegGetValue.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(value))),
uintptr(pointerStringWithoutError(subKey)),
uintptr(pointerStringWithoutError(value)),
uintptr(RRF_RT_REG_SZ),
0,
0,
Expand All @@ -271,8 +271,8 @@ func RegGetString(hKey HKEY, subKey string, value string) string {
buf := make([]uint16, bufLen)
ret, _, _ := procRegGetValue.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(value))),
uintptr(pointerStringWithoutError(subKey)),
uintptr(pointerStringWithoutError(value)),
uintptr(RRF_RT_REG_SZ),
0,
uintptr(unsafe.Pointer(&buf[0])),
Expand All @@ -289,8 +289,8 @@ func RegGetUint32(hKey HKEY, subKey string, value string) (data uint32, errno in
var dataLen uint32 = uint32(unsafe.Sizeof(data))
ret, _, _ := procRegGetValue.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(value))),
uintptr(pointerStringWithoutError(subKey)),
uintptr(pointerStringWithoutError(value)),
uintptr(RRF_RT_REG_DWORD),
0,
uintptr(unsafe.Pointer(&data)),
Expand All @@ -303,8 +303,8 @@ func RegGetUint32(hKey HKEY, subKey string, value string) (data uint32, errno in
func RegSetKeyValue(hKey HKEY, subKey string, valueName string, dwType uint32, data uintptr, cbData uint16) (errno int) {
ret, _, _ := procRegSetKeyValue.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(valueName))),
uintptr(pointerStringWithoutError(subKey))),
uintptr(pointerStringWithoutError(valueName))),
uintptr(dwType),
data,
uintptr(cbData))
Expand All @@ -316,24 +316,24 @@ func RegSetKeyValue(hKey HKEY, subKey string, valueName string, dwType uint32, d
func RegDeleteKeyValue(hKey HKEY, subKey string, valueName string) (errno int) {
ret, _, _ := procRegDeleteKeyValue.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(valueName))))
uintptr(pointerStringWithoutError(subKey)),
uintptr(pointerStringWithoutError(valueName)))

return int(ret)
}

func RegDeleteValue(hKey HKEY, valueName string) (errno int) {
ret, _, _ := procRegDeleteValue.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(valueName))))
uintptr(pointerStringWithoutError(valueName)))

return int(ret)
}

func RegDeleteTree(hKey HKEY, subKey string) (errno int) {
ret, _, _ := procRegDeleteTree.Call(
uintptr(hKey),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))))
uintptr(pointerStringWithoutError(subKey)))

return int(ret)
}
Expand All @@ -355,8 +355,8 @@ func RegEnumKeyEx(hKey HKEY, index uint32) string {

func OpenEventLog(servername string, sourcename string) HANDLE {
ret, _, _ := procOpenEventLog.Call(
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(servername))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(sourcename))))
uintptr(pointerStringWithoutError(servername)),
uintptr(pointerStringWithoutError(sourcename)))

return HANDLE(ret)
}
Expand Down Expand Up @@ -384,10 +384,10 @@ func CloseEventLog(eventlog HANDLE) bool {
func OpenSCManager(lpMachineName, lpDatabaseName string, dwDesiredAccess uint32) (HANDLE, error) {
var p1, p2 uintptr
if len(lpMachineName) > 0 {
p1 = uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpMachineName)))
p1 = uintptr(pointerStringWithoutError(lpMachineName))
}
if len(lpDatabaseName) > 0 {
p2 = uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpDatabaseName)))
p2 = uintptr(pointerStringWithoutError(lpDatabaseName))
}
ret, _, _ := procOpenSCManager.Call(
p1,
Expand All @@ -412,7 +412,7 @@ func CloseServiceHandle(hSCObject HANDLE) error {
func OpenService(hSCManager HANDLE, lpServiceName string, dwDesiredAccess uint32) (HANDLE, error) {
ret, _, _ := procOpenService.Call(
uintptr(hSCManager),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpServiceName))),
uintptr(pointerStringWithoutError(lpServiceName)),
uintptr(dwDesiredAccess))

if ret == 0 {
Expand All @@ -433,7 +433,7 @@ func StartService(hService HANDLE, lpServiceArgVectors []string) error {
} else {
lpArgs := make([]uintptr, l)
for i := 0; i < l; i++ {
lpArgs[i] = uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpServiceArgVectors[i])))
lpArgs[i] = uintptr(pointerStringWithoutError(lpServiceArgVectors[i]))
}

ret, _, _ = procStartService.Call(
Expand Down
2 changes: 1 addition & 1 deletion gdiplus.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var (
func GdipCreateBitmapFromFile(filename string) (*uintptr, error) {
var bitmap *uintptr
ret, _, _ := procGdipCreateBitmapFromFile.Call(
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(filename))),
uintptr(pointerStringWithoutError(filename)),
uintptr(unsafe.Pointer(&bitmap)))

if ret != Ok {
Expand Down
10 changes: 5 additions & 5 deletions kernel32.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ func CreateProcessA(lpApplicationName *string,
}

procCreateProcessA.Call(
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(*lpApplicationName))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpCommandLine))),
uintptr(pointerStringWithoutError(*lpApplicationName)),
uintptr(pointerStringWithoutError(lpCommandLine)),
uintptr(unsafe.Pointer(lpProcessAttributes)),
uintptr(unsafe.Pointer(lpThreadAttributes)),
uintptr(inherit),
Expand Down Expand Up @@ -293,7 +293,7 @@ func GetProcAddress(hProcess HANDLE, procname string) (addr uintptr, err error)
if procname == "" {
pn = 0
} else {
pn = uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(procname)))
pn = uintptr(pointerStringWithoutError(procname))
}

ret, _, err := procGetProcAddress.Call(uintptr(hProcess), pn)
Expand Down Expand Up @@ -328,7 +328,7 @@ func GetModuleHandle(modulename string) HINSTANCE {
if modulename == "" {
mn = 0
} else {
mn = uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(modulename)))
mn = uintptr(pointerStringWithoutError(modulename))
}
ret, _, _ := procGetModuleHandle.Call(mn)
return HINSTANCE(ret)
Expand Down Expand Up @@ -601,7 +601,7 @@ func SetConsoleTextAttribute(hConsoleOutput HANDLE, wAttributes uint16) bool {
func GetDiskFreeSpaceEx(dirName string) (r bool,
freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes uint64) {
ret, _, _ := procGetDiskFreeSpaceEx.Call(
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(dirName))),
uintptr(pointerStringWithoutError(dirName)),
uintptr(unsafe.Pointer(&freeBytesAvailable)),
uintptr(unsafe.Pointer(&totalNumberOfBytes)),
uintptr(unsafe.Pointer(&totalNumberOfFreeBytes)))
Expand Down
2 changes: 1 addition & 1 deletion oleaut32.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func VariantInit(v *VARIANT) {
}

func SysAllocString(v string) (ss *int16) {
pss, _, _ := procSysAllocString.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(v))))
pss, _, _ := procSysAllocString.Call(uintptr(pointerStringWithoutError(v)))
ss = (*int16)(unsafe.Pointer(pss))
return
}
Expand Down
21 changes: 16 additions & 5 deletions shell32.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
procSHBrowseForFolder = modshell32.NewProc("SHBrowseForFolderW")
procSHGetPathFromIDList = modshell32.NewProc("SHGetPathFromIDListW")
procShellExecute = modshell32.NewProc("ShellExecuteW")
procShellNotifyIconW = modshell32.NewProc("Shell_NotifyIconW")
)

func SHBrowseForFolder(bi *BROWSEINFO) uintptr {
Expand Down Expand Up @@ -89,19 +90,19 @@ func DragFinish(hDrop HDROP) {
func ShellExecute(hwnd HWND, lpOperation, lpFile, lpParameters, lpDirectory string, nShowCmd int) error {
var op, param, directory uintptr
if len(lpOperation) != 0 {
op = uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpOperation)))
op = uintptr(pointerStringWithoutError(lpOperation))
}
if len(lpParameters) != 0 {
param = uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpParameters)))
param = uintptr(pointerStringWithoutError(lpParameters))
}
if len(lpDirectory) != 0 {
directory = uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpDirectory)))
directory = uintptr(pointerStringWithoutError(lpDirectory))
}

ret, _, _ := procShellExecute.Call(
uintptr(hwnd),
op,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpFile))),
uintptr(pointerStringWithoutError(lpFile)),
param,
directory,
uintptr(nShowCmd))
Expand Down Expand Up @@ -146,8 +147,18 @@ func ShellExecute(hwnd HWND, lpOperation, lpFile, lpParameters, lpDirectory stri
func ExtractIcon(lpszExeFileName string, nIconIndex int) HICON {
ret, _, _ := procExtractIcon.Call(
0,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpszExeFileName))),
uintptr(pointerStringWithoutError(lpszExeFileName)),
uintptr(nIconIndex))

return HICON(ret)
}

// Shell_NotifyIconW Sends a message to the taskbar's status area.
func Shell_NotifyIconW(dwMessage string, lpData int) bool {
ret, _, _ := procShellNotifyIconW.Call(
0,
uintptr(pointerStringWithoutError(lpszExeFileName)),
uintptr(nIconIndex))

return bool(ret)
}
Loading

0 comments on commit d165716

Please sign in to comment.