The IDirectMusic::CreatePort method is used to create an object for a particular DirectMusic port.
HRESULT CreatePort(
REFCLSID rclsidPort,
LPDMUS_PORTPARAMS pPortParams,
LPDIRECTMUSICPORT *ppPort,
LPUNKNOWN pUnkOuter
);
If the method succeeds, the return value is S_OK, or S_FALSE if a requested parameter is not available.
If it fails, the method may return one of the following error values:
DMUS_E_DSOUND_NOT_SET |
E_INVALIDARG |
E_NOAGGREGATION |
E_NOINTERFACE |
E_OUTOFMEMORY |
E_POINTER |
By default, the port is inactive when it is created. It must be activated by a call to IDirectMusic::Activate or IDirectMusicPort::Activate.
If not all parameters could be obtained, then the DMUS_PORTPARAMS structure will be changed as follows to match the available parameters of the port.
On entry, the dwValidParams member of the structure indicates which members in the structure are valid. If the flag is not set for a member of the structure, then a default value is set for that parameter when the port is created.
On return, the flags in dwValidParams show which port parameters were set. If a particular parameter was not requested but was set to the default, then that flag is added to those passed in.
If the port supports a specified parameter, but the given value for the parameter is out of range, then the parameter value in *pPortParams will be changed. In this case, the flag in dwValidParams remains set, but S_FALSE will be returned to indicate that the value has been changed.
The following code shows how an application can request reverb capabilities and determine if they were obtained. (For an alternative way of checking and setting port properties, see Port Property Sets.)
DMUS_PORTPARAMS params;
ZeroMemory(¶ms, sizeof(params));
params.dwSize = sizeof(params);
params.dwValidParams = DMUS_PORTPARAMS_EFFECTS;
params.dwEffectFlags = DMUS_EFFECT_REVERB;
HRESULT hr = pDirectMusic->CreatePort(guidPort, ¶ms,
&port, NULL);
if (SUCCEEDED(hr))
{
fGotReverb = TRUE;
if (hr == S_FALSE)
{
if (!(params.dwValidParams & DMUS_PORTPARAMS_EFFECTS))
{
// Device does not support any effects
fGotReverb = FALSE;
}
else if (!(params.dwEffectFlags & DMUS_EFFECT_REVERB))
{
// Device understands effects,
// but could not allocate reverb
fGotReverb = FALSE;
}
}
}
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
Header: Declared in dmusicc.h.