C++ 创建用管理员方式运行的快捷方式 附:fopen()打开包含中文的路径

说创建不大准确,毕竟我写这个的目的是为了做个炉石传说拔线工具,实际实现的内容是将现有的快捷方式用程序勾上用管理员方式运行。

后面我会把工具源码、已经编译好的文件发出来。

想要学会一种fopen()打开包含中文的路径的方法的话可以仔细看看源码,这里我就不分离成案例了。

#include <iostream>
#include <stringapiset.h>

using namespace std;
typedef unsigned char byte;

bool hashSuffix(string str, string &suffix) { return str.size() >= suffix.size() && !str.compare(str.size() - suffix.size(), str.size(), suffix); }
wchar_t *toWChar(char *str, UINT codePage);
int lnkUpLevel(char *fileName);

static string fileSuffix = ".lnk";

int main(int argc, char** argv) {
    for (int i = 1; i < argc; i++) lnkUpLevel(argv[i]);
    return 0;
}

int lnkUpLevel(char *fileName) {
    if (!hashSuffix(string(fileName), fileSuffix)) return 0;
    FILE *file = fopen(fileName, "r+");
    if (file == NULL) {
        file = _wfopen(toWChar(fileName, CP_UTF8), L"r+");
        if (file == NULL) return 0;
    }
    fseek(file, 0x15, SEEK_SET);
    byte bit = 0x20;
    fwrite(&bit, 1, 1, file);
    fclose(file);
}

wchar_t *toWChar(char *str, UINT codePage) {
    int len = MultiByteToWideChar(codePage, 0, str, strlen(str), NULL, 0);
    wchar_t *w_char = new wchar_t[len + 1];
    MultiByteToWideChar(codePage ,0, str, strlen(str), w_char, len);
    w_char[len] = '\0';
    return w_char;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值