dongxian6715 2013-07-30 11:50
浏览 668
已采纳

调用Windows函数(获取字体目录)

I try to find out the font folder on a windows installation. AFAICS the proposed way is to call SHGetKnownFolderPath in Shell32.dll with KNOWNFOLDERID set to FOLDERID_Fonts.

I have no idea what to pass to the Call function in the code below:

package main

import (
    "syscall"
)

func main() {
    // HRESULT SHGetKnownFolderPath(
    //   _In_      REFKNOWNFOLDERID rfid,
    //   _In_      DWORD dwFlags,
    //   _In_opt_  HANDLE hToken,
    //   _Out_     PWSTR *ppszPath
    // );

    var (
        shell32             = syscall.NewLazyDLL("Shell32.dll")
        shGetKnowFolderPath = shell32.NewProc("SHGetKnownFolderPath")

        // Doesn't work, of course:
        folderId int
        flags    int
        handle   int
        retval   int
    )

    shGetKnowFolderPath.Call(uintptr(folderId), uintptr(flags), uintptr(handle), uintptr(retval))
}

Any idea? (I guess a workaround for now would be to stick to %windir%\Fonts, but I'd like to get a proper solution).

References:

  • 写回答

4条回答 默认 最新

  • duanpa1898 2019-09-19 21:54
    关注

    golang.org/x/sys/windows now has a wrapper for SHGetKnownFolderPath, so this is much easier:

    package main
    
    import (
        "fmt"
    
        "golang.org/x/sys/windows"
    )
    
    func main() {
        path, err := windows.KnownFolderPath(windows.FOLDERID_Fonts, 0)
        if err != nil {
            fmt.Println(err)
            return
        }
        fmt.Println(path)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?