QT Powrprof.h函数未在范围内声明

时间:2017-06-13 20:42:12

标签: c++ windows qt winapi mingw

我正在尝试在QT中使用powrprof.h函数,特别是PowerGetActiveScheme函数,并且遇到了一些麻烦。 我已经开始了一个新项目,这是我的main.cpp:

#include "mainwindow.h"
#include <QApplication>
#include "Windows.h"
#include "winbase.h"
#include "powrprof.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    GUID* gp = new GUID;
    GUID** gpp = &gp;
    PowerGetActiveScheme(NULL,gpp);
    return a.exec();
}

当我尝试构建/运行它时,QT给了我这个错误:

C:\Users\Jared\Documents\Qt\DebugTest\main.cpp:18: error: 'PowerGetActiveScheme' was not declared in this scope
 PowerGetActiveScheme(gpp);
                         ^

通过将#include "powrprof.h替换为

,我能够在Visual Studio中完成此工作
extern "C" {

#include <PowrProf.h>
}
#pragma comment(lib, "powrprof.lib")

但这在QT中不起作用,它告诉我它忽略了#pragma评论。

到目前为止,我已经尝试过:

将C:\ Qt \ Tools \ mingw530_32 \ i686-w64-mingw32 \ include \中的Powrprof.h文件替换为来自 C:\ Program Files(x86)\ Windows Kits \ 10 \ Include \ 10.0.15063.0 \ um \ 然后给了我错误:

C:\Qt\Tools\mingw530_32\i686-w64-mingw32\include\powrprof.h:18: error: powerbase.h: No such file or directory

然后我将powerbase.h从C:\ Program Files(x86)\ Windows Kits \ 10 \ Include \ 10.0.15063.0 \ um \复制到C:\ Qt \ Tools \ mingw530_32 \ i686-w64-mingw32 \ include \

然后给了我这个错误:C:\Qt\Tools\mingw530_32\i686-w64-mingw32\include\powrprof.h:19: error: powersetting.h: No such file or directory

所以再一次,我将powersetting.h复制到目录。

然后我把它留给了我现在的所有这些错误:

C:\Qt\Tools\mingw530_32\i686-w64-mingw32\include\powerbase.h:71: error: '_Out_writes_bytes_opt_' has not been declared
 _Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer,
 ^

C:\Qt\Tools\mingw530_32\i686-w64-mingw32\include\powerbase.h:71: error: expected ',' or '...' before 'PVOID'
 _Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer,
                                            ^

C:\Qt\Tools\mingw530_32\i686-w64-mingw32\include\powrprof.h:1025: error: '_Out_writes_bytes_opt_' has not been declared
 _Out_writes_bytes_opt_(*pBufferSize) PBYTE  pReturnBuffer,
 ^

C:\Qt\Tools\mingw530_32\i686-w64-mingw32\include\powrprof.h:1025: error: expected ',' or '...' before 'PBYTE'
 _Out_writes_bytes_opt_(*pBufferSize) PBYTE  pReturnBuffer,
                                      ^

当然,

C:\Users\Jared\Documents\Qt\DebugTest\main.cpp:14: error: 'PowerGetActiveScheme' was not declared in this scope
 PowerGetActiveScheme(gpp);
                         ^

我还尝试将相关标题放在本地项目文件夹中,尝试在.pro文件中使用LIBS + =来包含.libs,如某些答案中所建议的那样,使用add existing files函数添加两者.h和.lib文件,以及我忘记的其他一些东西。

这是我的.pro文件(新项目,以前的调试尝试未显示):

#-------------------------------------------------
#
# Project created by QtCreator 2017-06-13T12:51:15
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = DebugTest
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0


SOURCES += \
        main.cpp \
        mainwindow.cpp

HEADERS += \
        mainwindow.h

FORMS += \
        mainwindow.ui

非常感谢任何和所有帮助。

如果它很重要,那么我最初尝试做的就是创建一个程序,根据它是插入还是通过电池自动切换笔记本电脑上的电源计划。

0 个答案:

没有答案