Solved

mciSendString examples wanted

Posted on 1998-03-24
8
1,603 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Three Considerations for Containers

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read our article on Experts Exchange.

 

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
 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

623 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