我正在写一个程序来控制CD驱动器。带来错误“对'mciSendCommandA @ 16'的未定义引用”和“未定义引用'winmain @ 16'"。请帮助消除错误 [英] Am writing a program to control CD drive. Brings errors "undefined reference to 'mciSendCommandA@16' " and " undefined reference to 'winmain@16' ". Please help eliminate errors
本文介绍了我正在写一个程序来控制CD驱动器。带来错误“对'mciSendCommandA @ 16'的未定义引用”和“未定义引用'winmain @ 16'"。请帮助消除错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <tchar.h>
#include <windows.h>
#include <mmsystem.h> // for MCI function
//link to winmm.lib (usually included in project setting)
#pragma comment(lib, "winmm")
void ControlCdTray(TCHAR drive, DWORD command)
{
//Not used here, only for debug
MCIERROR mciError=0;
//flags forMCI command
DWORD mciFlags=MCI_WAIT|MCI_OPEN_SHAREABLE|
MCI_OPEN_TYPE|MCI_OPEN_TYPE_ID|MCI_OPEN_ELEMENT;
//open drive device and get device ID
TCHAR elementName[]={drive};
MCI_OPEN_PARMS mciOpenParms={0};
mciOpenParms.lpstrDeviceType=(LPCTSTR)MCI_DEVTYPE_CD_AUDIO;
mciOpenParms.lpstrElementName=elementName;
mciError=mciSendCommand(0,
MCI_OPEN, mciFlags, (DWORD_PTR)&mciOpenParms);
//Ejecting or closing tray using device ID
MCI_SET_PARMS mciSetParms={0};
mciFlags=MCI_WAIT|command;//command is send by caller
mciError=mciSendCommand(mciOpenParms.wDeviceID,
MCI_SET, mciFlags, (DWORD_PTR)&mciSetParms);
//close device ID
mciFlags=MCI_WAIT;
MCI_GENERIC_PARMS mciGenericParms={0};
mciError=mciSendCommand(mciOpenParms.wDeviceID,
MCI_CLOSE, mciFlags,(DWORD_PTR)&mciGenericParms);
}
//Eject drive tray
void EjectCdTray(TCHAR drive)
{
ControlCdTray(drive, MCI_SET_DOOR_CLOSED);
}
//Retract drive tray
void CloseCdTray(TCHAR drive)
{
ControlCdTray(drive,MCI_SET_DOOR_CLOSED);
}
int_tmain(int argc,_TCHAR* argv[])
{
EjectCdTray(TEXT('E')); //driveletter hardcoded
CloseCdTray(TEXT('E'));
return 0;
}
推荐答案
显然是一些链接器或项目问题。我的提示是,您的构建目标的项目设置中存在一些不匹配。最简单的方法是启动一个新项目(使用正确的设置)并复制所有代码或将这些项目设置与您的项目设置进行比较。我猜你做了一个dll项目,但想要一个控制台解决方案。
It is clearly some linker or project issues. My tip is, that you have some mismatch in your project settings for your build target. The easiest way is to start a new project (with the correct settings) and copy all your code or compare such project settings with yours. I guess you made a dll project but want a console solution.
请注意
Please note
引用:
int_tmain(int argc,_TCHAR * argv [])
int_tmain(int argc,_TCHAR* argv[])
应该是
Should be instead
int _tmain(int argc,_TCHAR* argv[])
CPallini你的解决方案解决了winmain @ 16的问题。但是,这行代码仍然存在问题。我不知道出了什么问题。带来未定义的'mciSendCommandA @ 16'引用'
mciError = mciSendCommand(mciOpenParms.wDeviceID,MCI_CLOSE,mciFlags,(DWORD_PTR)& mciGenericParms);
CPallini your solution solves the problem of winmain@16. However, this line of code is still problematic. I dont know what is wrong. Brings "undefined reference to 'mciSendCommandA@16'
mciError = mciSendCommand(mciOpenParms.wDeviceID,MCI_CLOSE, mciFlags,(DWORD_PTR)&mciGenericParms);
这篇关于我正在写一个程序来控制CD驱动器。带来错误“对'mciSendCommandA @ 16'的未定义引用”和“未定义引用'winmain @ 16'"。请帮助消除错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文