【问题标题】:USe function from user32.dll in Qt4 application在 Qt4 应用程序中使用 user32.dll 中的函数
【发布时间】:2010-10-22 05:38:39
【问题描述】:

我无法在我的 Qt 应用程序中使用函数 MonitorFromPoint。我在 Windows XP 上有带有 mingw 的最新 Qt SDL 2010.05

#include <QtCore/QCoreApplication>
#include<windows.h>
#include <winuser.h>
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    POINT pt;
    MonitorFromPoint(pt,2);
    return a.exec();
}

我将此添加到 .pro 文件中

LIBS+= -luser32

结果是

g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"..\include\QtCore" -I"..\include" -I"..\include\ActiveQt" -I"tmp\moc\debug_shared" -I"..\testUser32" -I"." -I"..\mkspecs\win32-g++" -o tmp\obj\debug_shared\main.o ..\testUser32\main.cpp

mingw32-make[1]: Leaving directory `C:/Qt/2010.05/qt/testUser32-build-desktop'

mingw32-make: Leaving directory `C:/Qt/2010.05/qt/testUser32-build-desktop'

..\testUser32\main.cpp: In function 'int main(int, char**)':

..\testUser32\main.cpp:8: error: 'MonitorFromPoint' was not declared in this scope

mingw32-make[1]: *** [tmp/obj/debug_shared/main.o] Error 1

mingw32-make: *** [debug-all] Error 2

The process "C:/Qt/2010.05/mingw/bin/mingw32-make.exe" exited with code %2.
Error while building project testUser32 (target: Desktop)
When executing build step 'Make'

IRc 上有人说这是一个 mingw 问题,我应该使用 visualc 编译器。切换编译器需要时间,也许我会发现其他问题。我从wingdi.h 导入了函数,没有任何问题。 我需要更好地解释这个问题,你如何解决它和解决方案

附:我正在尝试在多显示器系统中获取屏幕几何图形,QDesktopWidget 不起作用,请参阅主题Capture multiple screens desktop image using Qt4

【问题讨论】:

  • 我不确定我的评论会有多有趣。但是,您可以手动包含函数 signature.LOL,尽管它不是永久性的补救措施。但它应该可以工作。

标签: c++ qt winapi linker mingw


【解决方案1】:

我找到了这个http://www.mingw.org/wiki/Use_more_recent_defined_functions

我再次查看了标题是否定义了函数,我看到了这个

#if (_WIN32_WINNT >= 0x0500 || _WIN32_WINDOWS >= 0x0410)
WINUSERAPI HMONITOR WINAPI MonitorFromPoint(POINT,DWORD);

这意味着此方法不适用于旧版本的 Windows。 解决方案是定义

#include <QtCore/QCoreApplication>
#define _WIN32_WINNT  0x0500
#include<windows.h>
#include <winuser.h>
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    POINT pt;
    MonitorFromPoint(pt,2);
    return a.exec();
}

【讨论】:

  • 最好在你的项目文件中定义这个环境变量。它不应该因源文件而异;您最终会为 Windows 2000 编译一半源代码,而为 Windows XP 编译另一半源代码。这尤其痛苦,因为某些类型添加了新成员,因此它们的sizeof 发生了变化。 (这就是为什么这样的结构有一个cb 字段 - Windows 会检查它以查看您使用了哪些成员)
猜你喜欢
  • 2018-10-30
  • 1970-01-01
  • 1970-01-01
  • 2012-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-26
  • 2013-08-15
相关资源
最近更新 更多