错误:在此范围内未声明“ SHGetKnownFolderPath”

问题描述 投票:0回答:1

我之前知道这个问题,我的CPP文件是:

#include <shlobj.h>
int main(int argc, char *argv[])
{
    PWSTR pszPath;
    HRESULT hr = SHGetKnownFolderPath(&FOLDERID_Startup,0,NULL,&pszPath);
}

而且我正在使用Linux Mingw编译器通过此命令为Windows编译它:

i686-w64-mingw32-gcc hub.cpp

x86_64-w64-mingw32-g++ hub.cpp

我得到:

In function ‘int main(int, char**)’:
error: ‘SHGetKnownFolderPath’ was not declared in this scope
                 &pszPath);
                     ^

将这些添加到标题无济于事,并且出现相同的错误:

#define WINVER 0x0600
#include <windows.h>

#define WINVER 0x0600
#define _WIN32_WINNT 0x0600

并且我查看了[[shlobj.h,并且其中包含SHGetKnownFolderPath

我该如何解决?

编辑

我的朋友

ssbssa]的更改建议在注释中放入#define _WIN32_WINNT 0x0600 before #include <shlobj.h>,引发新的错误和新的注释:

hub.cpp: In function ‘int main(int, char**)’: hub.cpp:8:69: error: invalid initialization of reference of type ‘const KNOWNFOLDERID& {aka const _GUID&}’ from expression of type ‘const GUID* {aka const _GUID*}’ HRESULT hr = SHGetKnownFolderPath(&FOLDERID_Startup,0,NULL,&pszPath); ^ In file included from hub.cpp:2:0: /usr/share/mingw-w64/include/shlobj.h:755:10: note: in passing argument 1 of ‘HRESULT SHGetKnownFolderPath(const KNOWNFOLDERID&, DWORD, HANDLE, WCHAR**)’ STDAPI SHGetKnownFolderPath (REFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, PWST
我可以看到错误说,它期望有一个指针,并且我给了他一个地址,但是我不知道如何以正确的方式声明它。

我知道之前问过这个问题,我的CPP文件是:#include

int main(int argc,char * argv []){PWSTR pszPath; HRESULT hr = SHGetKnownFolderPath(&FOLDERID_Startup,0,NULL,&...

c++ linux mingw mingw32
1个回答
0
投票
尝试在#define NTDDI_VERSION 0x06000000之前添加#include <windows.h>
© www.soinside.com 2019 - 2024. All rights reserved.