zoukankan      html  css  js  c++  java
  • C++ 将filesystem::path转换为const BYTE*

    std::string s = fs::temp_directory_path().append(filename).string();
    
    LPCBYTE str = reinterpret_cast<LPCBYTE>(s.c_str()),
    RegSetValueExA的实战示例:
    // using std::string...
    
    HKEY newValue;
    
    // don't use RegOpenKey()! It is provided only for backwards compatibility with 16bit apps...
    if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", 0, KEY_SET_VALUE, &newValue) == 0)
    {
        // this may lose data for non-ASCII characters!
        std::string s = fs::temp_directory_path().append(filename).string();
    
        // this will convert the ANSI string to Unicode for you...
        RegSetValueExA(newValue, "myprogram", 0, REG_SZ, reinterpret_cast<LPCBYTE>(s.c_str()), s.size()+1);
    
        RegCloseKey(newValue);
    }
    
    return 0;
    
    // using std::wstring...
    
    HKEY newValue;
    
    // don't use RegOpenKey()! It is provided only for backwards compatibility with 16bit apps...
    if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\Microsoft\Windows\CurrentVersion\Run", 0, KEY_SET_VALUE, &newValue) == 0)
    {
        // no data loss here!
        std::wstring s = fs::temp_directory_path().append(filename).wstring();
    
        // no ANSI->Unicode conversion is performed here...
        RegSetValueExW(newValue, L"myprogram", 0, REG_SZ, reinterpret_cast<LPCBYTE>(s.c_str()), (s.size()+1) * sizeof(WCHAR));
    
        RegCloseKey(newValue);
    }
    
    return 0;
  • 相关阅读:
    ThreadLocal的分享
    remot debug
    小计-git
    入坑HttpServletRequest.getParameterMap
    基于线程池和连接池的Http请求
    spring,maven,dubbo配置
    springMVC,mybatis配置事务
    寻找数组的主元素问题的解法
    关于最大子序列和问题以及相关衍生问题的分析
    关于选择问题的一些思路.
  • 原文地址:https://www.cnblogs.com/strive-sun/p/13918044.html
Copyright © 2011-2022 走看看