Need help with my code

polaris · · 406 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Trying to change my desktops wallpaper i wrote this code using what i could understand from the API, But the wallpaper just turns black... package main</p> <pre><code>import ( &#34;fmt&#34; &#34;syscall&#34; &#34;time&#34; &#34;unsafe&#34; ) var ( user32 = syscall.NewLazyDLL(&#34;user32.dll&#34;) //user32.dll systemParametersInfo = user32.NewProc(&#34;SystemParametersInfoA&#34;) ) func main() { ImageLocA := `C:\Users\satur\Desktop\a.jpg` ImageLocB := `C:\Users\satur\Desktop\b.jpg` fmt.Println(&#34;Setting BG to: &#34; + ImageLocA) ret, _, _ := systemParametersInfo.Call(20, 0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(ImageLocA))), 0x01) fmt.Println(ret) time.Sleep(5 * time.Second) fmt.Println(&#34;Setting BG to: &#34; + ImageLocB) ret, _, _ = systemParametersInfo.Call(20, 0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(ImageLocB))), 0x01) fmt.Println(ret) } </code></pre> <hr/>**评论:**<br/><br/>SaturnsVoid: <pre><p>I figured it out, I was using SystemParametersInfoA when i needed SystemParametersInfoW!</p> <p>Info: <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724947(v=vs.85).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/windows/desktop/ms724947(v=vs.85).aspx</a></p> <p>Fixed Working Code: package main</p> <pre><code>import ( &#34;fmt&#34; &#34;syscall&#34; &#34;time&#34; &#34;unsafe&#34; ) var ( user32 = syscall.NewLazyDLL(&#34;user32.dll&#34;) //user32.dll systemParametersInfo = user32.NewProc(&#34;SystemParametersInfoW&#34;) ) func main() { ImageLocA := `C:\Users\satur\Desktop\a.jpg` ImageLocB := `C:\Users\satur\Desktop\b.jpg` fmt.Println(&#34;Setting BG to: &#34; + ImageLocA) ret, _, _ := systemParametersInfo.Call(20, 0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(ImageLocA))), 2) fmt.Println(ret) time.Sleep(5 * time.Second) fmt.Println(&#34;Setting BG to: &#34; + ImageLocB) ret, _, _ = systemParametersInfo.Call(20, 0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(ImageLocB))), 2) fmt.Println(ret) } </code></pre></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

406 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传