mciSendString examples wanted

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
vinny5Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vinny5Author Commented:
Edited text of question
0
vinny5Author Commented:
Adjusted points to 400
0
rajesh032097Commented:
"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
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

vinny5Author Commented:
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
vinny5Author Commented:
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
jtwine100697Commented:
  "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
chensuCommented:
Do you want the examples using mciSendCommand instead of mciSendString?
0
rajesh032097Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.