16,213
社区成员
发帖
与我相关
我的任务
分享
bool Beep(int nfre,int nts)
{
#ifdef Q_OS_WIN
qDebug()<<"win";
typedef int (*winBeep)(unsigned long ,unsigned long); //定义函数指针,以备调用 unsigned long == dword
QLibrary winlib("Kernel32.dll");
if (winlib.load()) //判断是否正确加载
{
winBeep pBeep = (winBeep)winlib.resolve("Beep"); //援引 Beep() 函数
if (pBeep) //是否成功连接上 add() 函数
{
bool r = pBeep(nfre,nts);
return r;
}
}
#else
QApplication::beep();
return true;
#endif
return false;
}
QTDIR/src/corelib/plugin/plugin.pri
win32 {
SOURCES += plugin/qlibrary_win.cpp
}
unix {
SOURCES += plugin/qlibrary_unix.cpp
}
你第一种方法用完后加个unload看看extern "C" //由于是C版的dll文件,在C++中引入其头文件要加extern "C" {},注意
{
#include "C:/Program Files/Microsoft SDKs/Windows/v7.0A/Include/Windows.h"
}
bool AlertItemFrame::BeepEx(int nfre,int nts)
{
#ifdef Q_OS_WIN
// qDebug()<<"win";
// typedef int (*winBeep)(unsigned long ,unsigned long); //定义函数指针,以备调用 unsigned long == dword
// QLibrary winlib("Kernel32.dll");
// if (winlib.load()) //判断是否正确加载
// {
// winBeep pBeep = (winBeep)winlib.resolve("Beep"); //援引 Beep() 函数
// if (pBeep) //是否成功连接上 add() 函数
// {
// bool r = pBeep(nfre,nts);
// return r;
// }
// }
Beep(nfre,nts);
#else
QApplication::beep();
return true;
#endif
return false;
}