尝试使用可执行文件打开 url 地址
Trying to open up a url address with an executable
我正在尝试在我的 c++ 项目中使用 ShellExecute 打开用户输入 url,但在项目中创建 main 函数时遇到困难。
目前我有
#include<Windows.h>
#include<stdlib.h>
#include<shellApi.h>
int findIE(const char*);
int main()
{
const char* url;
findIE(url);
return 0;
}
/**
* Open the default browser to the specified URL.
*
* param url WebAddress to open a browser to.
*
* returns
* If the function succeeds, it returns a value greater than 32.
* Otherwise,it returns an error code as defined in the ShellExecute documentation.
*
* remarks
* The function uses the headerfiles: windows.h, stdlib.h, shellapi.h.
* The url is converted into a unicode string before being used.
**/
int findIE(const char* cUrl)
{
ShellExecute(NULL, "open", cUrl, NULL, NULL, SW_SHOWDEFAULT);
return 0;
}
我尝试转到我的可执行文件并运行它,但没有任何显示......我可以得到一些关于我下一步的建议吗?
该程序应运行:
findIE.exe websitename.com
然后打开默认浏览器以 websitename.com
感谢您的回复!
该程序应运行:
findIE.exe websitename.com
啊,那你需要将命令行参数传递给main
.
至少:
int main( int argc, char ** argv )
{
if ( argc >= 2 )
{
findIE( argv[1] );
}
return 0;
}
您需要初始化变量 'url'。
例如:
int main()
{
const char* url = "www.google.com"
findIE(url);
return 0;
}
如果你想使用用户输入,你将不得不去掉char变量的恒常性。
相关文章:
- 将数组的地址分配给变量并删除
- 空基优化子对象的地址
- C++ 指针的内存地址和指向数组的内存地址如何相同?
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 如何在c++程序中找到函数的地址
- 向量元素的引用地址与它所指向的向量元素的地址不同.为什么
- 被解释为低级别const的const对象的地址
- 将地址分配给本地指针后,公共对象的变量将消失
- 为什么我在leetcode上收到AddressSanitizer:地址0x602000000058上的堆缓冲区溢出错误
- 内联程序集printf将整数解释为地址
- 为什么指针不写入类的地址?
- 如何在C++中获取该对象的类声明中对象的地址?
- 通过按地址访问变量
- 当一个新对象被分配到它的地址时,对象是否必须被销毁
- 函数名是c中该函数的第一条指令的地址吗
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 如何使用url确定网站协议
- 访问其他网站后如何获得完整(精确)的URL / QUrl地址?
- 尝试使用可执行文件打开 url 地址
- 如何确定 URL 是否为 C/C++ 中的 IP 地址