Am having trouble in opening the CD drive door on visual C++ 2008 using the mciSendString API i get an error
it also happens with wingw
: error LNK2001: unresolved external symbol __imp__mciSendStringA@16
:fatal error LNK1120: 1 unresolved externals
it also happens with wingw
#include <windows.h>
#include <commctrl.h>
#include <Mmsystem.h>
#define ID_BUT 1
char cname[]="dfds";
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HWND hwnd;
HINSTANCE hInst;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrev,LPSTR CmdLine,int nCmd)
{
WNDCLASSEX wc={0};
MSG msg;
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = cname;
wc.hIcon = LoadIcon(0,IDI_APPLICATION);
wc.hIconSm = LoadIcon(0,IDI_APPLICATION);
wc.hCursor = LoadCursor(0,IDC_ARROW);
wc.cbSize = sizeof(WNDCLASSEX);
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
if(!RegisterClassEx(&wc))
return 1;
hwnd = CreateWindowEx(0,cname,"",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,200,200,0,0,hInst,0);
ShowWindow(hwnd,nCmd);
while(GetMessage(&msg,0,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
HWND butt;
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wparam,LPARAM lparam)
{
switch(message)
{
case WM_CREATE:
butt = CreateWindowEx(0,WC_BUTTON,"Open",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,10,10,100,25,hwnd,(HMENU)ID_BUT,0,0);
break;
case WM_COMMAND:
switch(wparam)
{
case ID_BUT:
mciSendString("Set CDAudio Door Open", NULL, 0, NULL);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wparam,lparam);
}
return 0;
}
Try using lowercase for the actual media command part of the string, ie, "set CDAudio door open"
I seem to remember that mci is picky about that.
I seem to remember that mci is picky about that.
Here is some assembly code that I hope will help you.
; open_cd.asm
;
include \masm32\include\masm32rt.inc
include \masm32\include\winmm.inc
includelib \masm32\lib\winmm.lib
.CODE
Drive_h db "open h: type cdaudio alias cd", 0
Open_CD db "set cd door open", 0
Close_CD db "set cd door closed", 0
start:
invoke mciSendString, OFFSET Drive_h, 0, 0, 0
invoke mciSendString, OFFSET Open_CD, 0, 0, 0
invoke mciSendString, OFFSET Close_CD, 0, 0, 0
invoke ExitProcess,0
end start
@homer that still doesn't work. look at the error message it seems to come from the linker its like mciSendString() doesn't exist but i checked the header file and the prototypes are there.
also MINGW gives a similar error
also MINGW gives a similar error
undefined reference to ` mciSendStringA@16'
i solved it. apparently i had to link against the library winmm.lib
but still the door doesn't open the application just loads mcicda.dll and the quickly unloads it.
It works now, thanx guys!
considerably easier to use the ioctl method, the mci method is old and pretty much redundant..