-1

I am not a native C++ programmer, so I need some help with the following:

I got this code working:

#pragma comment(lib, "winmm.lib")

LPCWSTR openCDCommand = L"set cdaudio door open";
//comes from Windows.h, needs winmm.lib see header includes
int errCode = mciSendString(openCDCommand, 0, 0, 0);

Questions:

  • Do I need to work with LPCWSTR? Why didn't I find a System::String example?
  • How should I handle 'string concatination'? I cant simply do L"foo"+L"baar"?
  • Am I on the totally wrong way to play sounds with mciSendString? (actually I really want to use MCI Command and MCI sendString as i did in other projects before)
  • Is there another way to include the external function mciSendString so it can handle handles?
4

2 回答 2

1

这现在对我有用 - 花了一些时间,但也许将来这会帮助其他人:

#include "vcclr.h" // compile with /clr(!)
int Player::mciSendStringHandle(String ^ givenHandle)
{
    pin_ptr<const wchar_t> wch = PtrToStringChars(givenHandle);
    return mciSendString(wch, 0, 0, 0);
}
于 2013-05-01T16:56:34.543 回答
1
  1. mciSendString 的签名是

    MCIERROR mciSendString( LPCTSTR lpszCommand, LPTSTR lpszReturnString, UINT cchReturn, HANDLE hwndCallback);

因此,关于前 2 个参数,在 unicode 中它将是一个 wchar 指针,在多字节中它将是一个 char 指针。是签名。你无法改变这一点,你不应该担心这一点。

  1. std::wstring someString( L"Foo" ); someString.append( L"bar ");

  2. 我会使用核心音频 API、waveOut 或 DirectSound 播放声音。但是,不与mciSendString().

  3. 恐怕我不明白这个..你能解释得更好吗?

于 2013-05-07T14:16:25.733 回答