int OpenMyQueue(
LPWSTR wszPathName,
DWORD dwAccess,
DWORD dwShareMode,
QUEUEHANDLE *phQueue
)
{

HRESULT hr = S_FALSE;
DWORD dwFormatNameLength = 0;
WCHAR *wszFormatName = NULL;


// Validate the input parameters.
if ((wszPathName == NULL) || (phQueue == NULL))
{
return MQ_ERROR_INVALID_PARAMETER;
}


// Create a buffer for the direct format name.
dwFormatNameLength = wcslen(wszPathName) + 11;
wszFormatName = new WCHAR[dwFormatNameLength];

if (wszFormatName)
{


// Create the direct format name of the queue.
memset(wszFormatName, 0, dwFormatNameLength*sizeof(WCHAR));
// ************************************
// You must concatenate "DIRECT=OS:" and wszPathName into the
// wszFormatName buffer.
// wszFormatName = DIRECT=OS:" + wszPathName
// If the format name is too long for the buffer, return FALSE.
// ************************************

// Call MQOpenQueue to open the queue with the access and
// share mode provided by the caller.
hr = MQOpenQueue(
wszFormatName, // Direct format name of
the queue
dwAccess, // Access mode
dwShareMode, // Share mode
phQueue // OUT: Queue handle
);
delete [] wszFormatName;
if (FAILED(hr))
{
fprintf(stderr, "An error occurred in MQOpenQueue (error: 0x%x.)
\n",hr);
return hr;
}
}