所以我想制作一个简单的DLL在另一个程序中播放声音。我正在尝试使用播放功能,并且已经设置了它,但是当我在另一个程序中运行它时,我得到了默认的嘟嘟声。这是我的代码。声音不适用于PlaySound
export double sound_manage(const char* file_old,double handler)
{
/*
Handler values:
0 - Play sound
1 - Loop sound
2 - Stop sound
*/
bool good;
double ret;
double op;
if (handler == 0) op = SND_ASYNC;
if (handler == 1) op = SND_LOOP;
if (handler == 2) op = SND_PURGE;
LPCTSTR file;
file = LPCTSTR(file_old);
good = PlaySound(file,NULL,op);
ret = double(good);
return ret;
}
我已经在链接器中包含了winmib或其他东西,但是我不知道发生了什么。
任何帮助,非常感谢!
我试过了,但同样的事情发生。我不确定unicode,但我使用的是VC++ 2010,它告诉我如果我不投射是错误的。 – null 2014-10-18 22:57:28
请参阅[这里](http://stackoverflow.com/a/332086/33499)为什么类型转换可能是危险的。如果可能的话,你应该尽量避免它。您应该使用[MultiByteToWideChar](http://msdn.microsoft.com/zh-cn/library/dd319072%28v=vs.85%29.aspx)来转换字符串。但是如果你使用'PlaySoundA',它可能会更容易,应该避免类型转换。 – wimh 2014-10-19 11:03:51
我尝试了多字节宽字符,它说错了...另外,什么是PlaySoundA? (我是C++新手。) – null 2014-10-20 23:20:21