试图用可执行文件打开 url 地址

Trying to open up a url address with an executable

我正在尝试在我的 C++ 项目中使用 ShellExecute 打开用户输入 url,但我发现在项目中创建主函数时遇到困难。

目前我有

#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

感谢您的回复!

您需要初始化变量'url'。

例如:

int main()
{
const char* url = "www.google.com"
findIE(url);
return 0;
}

如果你想使用用户输入,你将不得不去掉 char 变量的常量。

The program should be run:

findIE.exe websitename.com

啊,那你需要pass command line arguments to main.

至少:

int main( int argc, char ** argv )
{
    if ( argc >= 2 )
    {
        findIE( argv[1] );
    }
    return 0;
}