in mciSendingString, can macro be used?

Hello.
I'd like to output the mp3 files.
So I googled, found mciSendString.

 
  mciSendString(LPCWSTR lpstrCommand, LPWSTR lpstrReturnString, UINT uReturnLength, HWND hwndCallback);


I don't know how exactly it works, so I used this function like this.

 
mciSendString(TEXT("play E:\\song1.mp3"),NULL,0,NULL);


Then, it played! I was so happy, but there's a problem.
mciSendString's 1st parameter should be macroed by using 'TEXT()'.
So if I want to next song, then I always write code like this.

1
2
mciSendString(TEXT("play E:\\song2.mp3"),NULL,0,NULL);
mciSendString(TEXT("play E:\\song3.mp3"),NULL,0,NULL);

... etc...

I just want to song's directory like this.

1
2
3
#define song1 E:\\song1.mp3

mciSendString(TEXT("play song1"),NULL,0,NULL);


so that it will be more useful, but TEXT() always recognize song1 not macro but text.

My questiong is this. macros & mciSendingString are compatible??
More exactly, in mciSendingString can macro be used?

Thx for reading! X)

-Chronospear
Last edited on
This has nothing to do with mciSendString.

The problem is that macro substitution does not occur inside quoted text (although that is not a problem really... it's a good thing).

example:
1
2
#define replaced yuk
cout << "I would be upset if the macro replaced any of this text";


despite 'replaced' occuring within my string, the compiler will fortunately not do macro substitution on it. If it did, it would be very difficult to have the literal text 'replaced' anywhere in my program!


But you really shouldn't be using macros for constants anyway. There are a million reasons why macros should be avoided.

Instead... you can use a constant:

 
const LPCTSTR song1 = TEXT("song1.mp3");


But then the problem becomes... how do you combine that constant with the "play" text? The answer is you'd do it just like any other string concatenation.

Note I'm going to get a little tricky here in order to try and keep this simple... bear with me:

1
2
3
4
5
6
7
#include <string>
//...
const std::string song1 = "E:\\song1.mp3";

//...
std::string command = "play " + song1; // append the strings together
mciSendStringA(command.c_str(), NULL, 0, NULL);  // then send the joined strings to mciSendString 


Note a few changes:
1) I'm using std::string to handle strings because it's way easier
2) I'm not using any macro garbage
3) I'm calling mciSendStringA instead of mciSendString. The difference between the two is that mciSendStringA takes normal char strings (meaning you don't need the TEXT() macro). mciSendString takes something called 'TCHAR' strings, which are retarded.
Last edited on
@Disch

Wuuuuaho!!
Thx alot!!!

Thanks to you, I've completely solved the problems!!
with string command and mciSendStringA, I could make a music player which has a music list, right?


Again, Thanks alot!
Have a good day!

-Chronospear
Topic archived. No new replies allowed.