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;
  • 相关阅读:
    webkit v8 chromium blink chrome 的关系
    webkit 系列
    工具使用过程中遇到问题
    ElasticSearch实战笔记
    办理北京市居住证需要哪些资料
    办理北京市居住证需要哪些资料
    MongoDB 笔记
    Javascript问题集锦
    sqlserver2016 management tool v18
    PostMan测试Web Service
  • 原文地址:https://www.cnblogs.com/strive-sun/p/13918044.html
Copyright © 2011-2022 走看看