Solved

mciSendString examples wanted

Posted on 1998-03-24
8
1,550 Views
Last Modified: 2013-11-19
Does anyone one know answers to these specific questions
using mciSendString?

For example to play an Audio CD I use
MCIERROR err = mciSendString("play cdaudio",NULL,0,NULL);
and to stop
MCIERROR err = mciSendString("stop cdaudio",NULL,0,NULL);
which works fine.

But I would like to know how to do the following:

1. Determine the number of Tracks on a CD. (use status)
2. Play the CD from a certain track number.(from pos to pos)
3. Play a midi file.

Thanks,  Btw the third question is there in case you know
it but not essential to get the points
0
Comment
Question by:vinny5
8 Comments
 

Author Comment

by:vinny5
ID: 1317201
Edited text of question
0
 

Author Comment

by:vinny5
ID: 1317202
Adjusted points to 400
0
 
LVL 2

Expert Comment

by:rajesh032097
ID: 1317203
"myaudio" is the alias name used in opening the device.
1. No of tracks on cd :
mciSendString("status myaudio number of tracks")
2. Play CD from certain track position
First set the time format to tracks using
mciSendString("set myaudio time format tmsf")
and then calling
mciSendString("play myaudio from %d", nTrackNo) where nTrackNo is the track number from which you want to start the playback. You can also specify the position upto which you want to play the CD and whether playback should be asynchronous or synchronous in the same command.
3. Stop CD player:
mciSendString("stop myaudio")

and finally call "close myaudio" when you are done with the device.
I haven't tried it for midi but it should be same. You can find all command specifications in the VC++ help.
Hope this helps.
0
 

Author Comment

by:vinny5
ID: 1317204
Thanks for the answer rajesh but I still need somethings cleared up.

>"myaudio" is the alias name used in opening the device.
why isnt that cdaudio?

1. No of tracks on cd :
mciSendString("status myaudio number of tracks")

where does the number get stored to and If I try to compile this line VC++ 5.0 tells me

error C2660: 'mciSendStringA' : function does not take 1 parameters

I dont know why the 'A' is there in  mciSendStringA but they are right. mciSendString needs

MCIERROR mciSendString( LPCTSTR lpszCommand,          LPTSTR lpszReturnString,
         UINT cchReturn,
         HANDLE hwndCallback );

so similarly the other mciSendString examples you said wont work.
Is there something that Im doing wrong?


0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:vinny5
ID: 1317205
Thanks for the answer rajesh but I could not get what you said to work.  I had some questions on your response:

>"myaudio" is the alias name used in opening the device.
why isnt that cdaudio?

1. No of tracks on cd :
mciSendString("status myaudio number of tracks")

where does the track number get stored to?
and If I try to compile this line VC++ 5.0 tells me

error C2660: 'mciSendStringA' : function does not take 1 parameters

I dont know why the 'A' is there in  mciSendStringA but they are right. mciSendString needs

MCIERROR mciSendString( LPCTSTR lpszCommand,          
         LPTSTR lpszReturnString,
         UINT cchReturn,
         HANDLE hwndCallback );

so similarly the other mciSendString examples you said wont work.
Is there something that Im doing wrong?


0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1317206
  "myaudio" is an alias that you specify when opening the desired MCI device.  From then on, you reference it by that alias.

   Look up (in the help system) the "status" MCI command.  It will tell you what parameters are required, and how to obtain results from the command(s).

   I have a simple class for playing MIDI (.MID/.RMI) files, if you are interested...

-=- James.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1317207
Do you want the examples using mciSendCommand instead of mciSendString?
0
 
LVL 2

Accepted Solution

by:
rajesh032097 earned 400 total points
ID: 1317208
Hi,
Alias is the name you specify for the device when you open it. It's needed since subsequent functions expect it as a parameter. Also it helps in distinguishing the devices easily especially if you have multiple devices on your machine ( say 2 CD players).
I thought you would refer to the correct syntax of the mciSendString() function by referrring to VC++ help. Anyway, mciSendString function has following syntax :
MCIERROR mciSendString( LPCTSTR lpszCommand, LPTSTR lpszReturnString,
UINT cchReturn, HANDLE hwndCallback );
 
lpszCommand -> string that identifies the command
lpszReturnString->place holder for return information
cchReturn->Size of lpszReturnString
hwndCallback->Window handle which can receive notification of mci commands if you specify "notify" flag in the command ( applicable only to a subset of the mci commands)

So, for e.g., your fisrt command can be written in following way :
void OpenCD()
{
char Buf[1000];
int nRet;
nRet = ::mciSendString("open cdaudio alias myplay shareable ",
      Buf, 1000, NULL);
if(nRet)
{
      ::mciGetErrorString(nRet, Buf,1000);
      ::MessageBox(NULL, Buf, NULL, MB_OK);
}

}

In case of command "status myaudio number of tracks" , or any command which is supposed to return some information, it would store it in lpszReturnString parameter after the function returns successfully.

All the mciSendString functions would be almost identical to the above unless you have a "notify" flag. If you want your application to continue without waiting for the playback, then you can specify "notify" flag in the lpszCommand string and then the handle of the window that you pass as fourth parameter is used by MCI for sending notifications. For example, if you want to receive notification after playback, your command may look like this:

void PlayCD(int nFrom, int nTo)
{
      char Buf[1000];
      int nRet;
      CString strMsg;
      strMsg.Format("play myplay from %d to %d notify",nFrom, nTo);
      nRet = ::mciSendString(strMsg.GetBuffer(1024),
            Buf, 1000, hWnd);
      if(nRet)
      {
            ::mciGetErrorString(nRet, Buf,1000);
            ::MessageBox(NULL, Buf, NULL, MB_OK);
      }
}

Again, I repeat, all  commands are well documented ( fortunately :-) ) in VC++ help section. And their usage is very simple and identical.
Also you need not worry about compiler output names since they are internal to the implementation. We need not bother about mciSendStringA. For the user, it's just mciSendString.
Hope this helps you now.



0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now