ShellExecute最终出现错误C2065不知道如何解决



我有一个计时器,之后应该执行一个本地html文件,但是我遇到了某种错误:

int delay = 120;
delay *= CLOCKS_PER_SEC;
clock_t now = clock();
while (clock() - now < delay);
string strWebPage = "file:///D:/project/site/scam.html";
strWebPage = "file:///" + strWebPage;
ShellExecute(NULL, NULL, NULL, strWebPage, NULL, SW_SHOWNORMAL);
return 0;

E0413没有合适的转换函数从"std::string";LPCWSTR"存在

我是c++新手,所以这可能是一个明显的解决方案。

谁能告诉我怎么修理它?

你有两个问题。

但首先,您应该总是花时间阅读文档。对于Win32函数,你可以通过在你最喜欢的搜索引擎中输入"msdn ShellExecute",然后点击"Lucky"按钮来找到一个已知的函数。

问题

ShellExecute()C函数。它不以std::string为参数。它需要指向字符的指针。因此:

std::string filename = "birds.html";
INT_PTR ok = ShellExecute( 
NULL,             // no window
NULL,             // use default operation 
filename.c_str(), // file to open
NULL,             // no args to executable files
NULL,             // no start directory
SW_SHOWNORMAL );
if (ok <= 32)
fooey();

请注意,我们将一个const char *传递给函数,作为

相关内容

最新更新