我正在尝试使用mciSendString函数在Qt中打开和关闭cd托盘。这是代码:
#include <windows.h>
MCIERROR mciSendString(LPCTSTR lpszCommand, LPTSTR lpszReturnString, UINT cchReturn, HANDLE hwndCallback);
void OpenCD()
{
mciSendString((LPCTSTR)"set cdaudio door open",(LPTSTR)NULL, (UINT)0, (HANDLE)NULL);
}
void CloseCD()
{
mciSendString((LPCTSTR)"set cdaudio door closed",(LPTSTR)NULL, (UINT)0, (HANDLE)NULL);
}
但是我得到了这个错误:“未定义的引用`mciSendStringW(wchar_t const *,wchar_t *,unsigned int,void *)'” 如何解决此错误并使用mciSendString函数没有任何问题?
答案 0 :(得分:0)
尝试将下一行添加到pro-file:
LIBS += path_to_lib/Winmm.lib
或
LIBS += path_to_lib/Winmm.dll
您还可以包含Mmsystem.h和Windows.h
Link
例如:
Pro文件包含已安装SDK的lib-file链接:
LIBS += $$quote(C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0A\\Lib\\WinMM.lib)
在cpp-file中:
#include "Windows.h"
#include "mmsystem.h"
//MCIERROR mciSendString(LPCTSTR lpszCommand, LPTSTR lpszReturnString, UINT cchReturn, HANDLE hwndCallback);
...
void MainWindow::on_pushButton_clicked() {
mciSendString((LPCTSTR)"set cdaudio door open",(LPTSTR)NULL, (UINT)0, (HWND__*)0);
}