I’m trying to use the mciSendString function to open and close the cd tray in Qt. Here is the code:
#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);
}
But I get this error: “ undefined reference to `mciSendStringW(wchar_t const*, wchar_t*, unsigned int, void*)' ” How can I fix this error and use the mciSendString function without any problem?
Try add one of the next lines to pro-file:
or
Also you can include Mmsystem.h and Windows.h
Link
For example:
Pro file inludes link to lib-file from installed SDK:
In cpp-file: