C Windows.h如何在Shellexecute中使用变量
C++ windows.h How to use variable in ShellExecute
我想问如何在 ShellExecute
在我的情况下,我想在文件中添加路径。
#include <windows.h>
#include <iostream>
int main()
{
std::string path={"C:UsersMeCLionProjectsstoragecmake-build-debugbookshop.txt"};
ShellExecute(NULL,"edit","path",NULL,NULL, SW_SHOWNORMAL);
return 0;
}
我已经尝试了c_str()
,但这无济于事。它正在编译没有错误,但TXT文件不反对。有线索吗?
您需要在字符串字面上逃脱后斜切,然后摆脱牙套:
std::string path = "C:\Users\Me\CLionProjects\storage\cmake-build-debug\bookshop.txt";
然后,您需要使用std::string::c_str()
方法将字符串传递给ShellExecute()
。而且由于您使用的是std::string
,因此应使用基于char
的ShellExecuteA()
而不是基于TCHAR
的ShellExecute()
:
ShellExecuteA(NULL, "edit", path.c_str(), NULL, NULL, SW_SHOWNORMAL);
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 将数组的地址分配给变量并删除
- 为"adjacent"变量赋值时出现问题
- enum是C++中的宏变量还是整数变量
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 用C++中的一个变量定义一个常量
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 你能重载对象变量名本身返回的内容吗
- 内置函数可查看CPP中的成员变量
- 是否可以初始化不可复制类型的成员变量(或基类)
- 尝试通过多个向量访问变量时,向量下标超出范围
- 试图让变量检查数组中的某些内容
- Cpp-Tuple使用带有变量的get
- 将包含C样式数组的对象初始化为成员变量(C++)
- 当vector是tje全局变量时,c++中vector的内存管理
- 通过多个头文件使用常量变量
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- C Windows.h如何在Shellexecute中使用变量
- 为什么ShellExecute不能使用包含文件路径的LPCSTR变量