LNK 2019 ShellExecuteEx unresolved external symbol Qt Creator

心不动则不痛 提交于 2019-12-13 03:17:00

问题


I work on Windows7 x64 in c++ language.

I created a project that open firefox browser when I show a marker to my web cam, using ShellExecuteEx function. My project works well with visual studio 2010.

But, when I try to run my project with Qt Creator, I get this error:

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

The code is:

#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 

I think problem is shell32.lib . If it is, I haven't this library in my pc. how can I fix it?

Can you help me?

Thanks in advance!


回答1:


It is very simple. Just right click the the project pro file and add external library. Choose system library, static and give the path of shell32.lib which is

C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib



回答2:


This is my solution to this problem :

in the .pro file : INCLUDEPATH += "C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib" ( the path to the file shellAPI.lib )

in my 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


来源:https://stackoverflow.com/questions/14286513/lnk-2019-shellexecuteex-unresolved-external-symbol-qt-creator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!