0

我用 c++ 语言在 Windows7 x64 上工作。

当我使用 ShellExecuteEx 函数向我的网络摄像头显示标记时,我创建了一个打开 Firefox 浏览器的项目。我的项目适用于 Visual Studio 2010。

但是,当我尝试使用 Qt Creator 运行我的项目时,我收到了这个错误:

main_cam.obj:-1: error: LNK2019: riferimento al simbolo esterno __imp__ShellExecuteExW@4 non risolto nella funzione _main
debug\cam.exe:-1: error: LNK1120: 1 esterni non risolti

代码是:

#include <iostream>
#include <stdio.h>
#include <string>   // for strings
#include <iomanip>  // for controlling float print precision
#include <sstream> // string to number conversion
#include <windows.h>
#include <ShellAPI.h>
include [...]
int main () {
[...]
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "firefox.exe";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
[...]
if (condition_is_verified) {

ShExecInfo.lpParameters = (LPCWSTR)"www.google.it";
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
}
[...]
}//end main 

我认为问题是 shell32.lib 。如果是,我的电脑中没有这个库。我该如何解决?

你能帮助我吗?

提前致谢!

4

2 回答 2

1

这很简单。只需右键单击项目 pro 文件并添加外部库。选择系统库,静态并给出shell32.lib的路径,即

C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib
于 2013-09-23T09:07:34.157 回答
1

这是我对这个问题的解决方案:

在 .pro 文件中:INCLUDEPATH += "C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib" (文件 shellAPI.lib 的路径)

在我的 mainwindow.h 中:

#define NOMINMAX // You have to do this for windows.h to work, else u'll get mistakes with datetime.h           
#include <windows.h> // (without the space)    
#pragma comment(lib, "Shell32.lib")    
#include <ShellAPI.h> // without space also
于 2014-05-23T09:29:18.897 回答