c++ - How Do I Get mciSendString to Work With Both Variables and Spaces? -
i have created program plays music in music directory , supports spaces, of google. however, don't want keep hard-coding song names, i'm wondering if can replace file name variable, , std::cin variable when program run. however, i want able play songs have spaces in names. made wrapper function (i think count one?) mcisendstring, , i'm trying able pass "name" parameter play. however, due complications lpcwstr , std::string, among other things, i'm having difficulty implementing this.
here's current music function:
void music(std::string strsongname,dword dwextraflag) { mcierror me = mcisendstring(text("open \"d:\\windows.old\\users\\myname\\desktop\\sounds\\music\\song name.mp3\""" type mpegvideo alias song1"), null, 0, 0); /* note want able play songs spaces in name */ if (me == 0) { me = mcisendstring(text("play song1 wait repeat"), null, 0, 0); mcisendstring(text("close song1"), null, 0, 0); } }
what want like:
void music(std::string strname,dword dwextraflag) { mcierror me = mcisendstring(text("open \"d:\\windows.old\\users\\myname\\desktop\\sounds\\music\\strnamevariablehere.mp3\""" type mpegvideo alias song1"), null, 0, 0); /* note want able play songs spaces in name */ if (me == 0) { me = mcisendstring(text("play song1 wait repeat"), null, 0, 0); mcisendstring(text("close song1"), null, 0, 0); } }
i make variable in main or other function , std::cin variable.
std::string strnameofsong = ""; std::cin >> strnameofsong;
then, call music like:
music(strnameofsong,0)
i mention can ignore "dwextraflags" argument if wish, have yet implement.
anyways, appreciate implementing new c++. however, don't want leave project unfinished, , wish complete before moving on.
i appreciate solutions, help, or tips. if want me more specific or provide more information formulate answer, glad so.
thank much.
edit: implemented ethan's suggestion. after adding things in , adding suggestion, program stops working shortly after typing in name of song want. i've tried debugging , reports:
"exception thrown @ 0x00047430 in program.exe: 0xc0000005: access violation writing location 0x6563696e."
here's added main function (aside ethan's suggestion):
static std::string strsongname = ""; std::cin >> strsongname; createthread(0, 0, (lpthread_start_routine)&music, &strsongname, 0, 0); // above createthread can play music while doing other things
debugging, values seem correct. however, exception , application stops working. how can have access violation?
another small change made ethan's suggestion:
mcierror me = mcisendstring((lpcwstr)(songfile.c_str()), null, 0, 0);
(i typecasted songfile giving me errors)
i changed example of path normal.
edit2:
fixed exception! because (in silly manner), forgot dereference pointer "strsongname". however, after space still isn't recognized, seems, debugged it. doesn't seem play songs when not have space, , yes adding .mp3 too.
how one?
void music(std::string strname,dword dwextraflag) { std::string songfile = "open \"d:\\windows.old\\users\\myname\\desktop\\sounds\\music\\"; songfile += strname + "\" type mpegvideo alias song1"; mcierror me = mcisendstring(songfile.c_str(), null, 0, 0); /* note want able play songs spaces in name */ if (me == 0) { me = mcisendstring(text("play song1 wait repeat"), null, 0, 0); mcisendstring(text("close song1"), null, 0, 0); } }
Comments
Post a Comment