To make an asynchronous call to a Microsoft System Center Configuration Manager 2007 endpoint, use ISmsMessaging::Post.

The following C++ example demonstrates how to asynchronously send a discovery data record report to a Configuration Manager 2007 endpoint on a local computer. The example demonstrates the following:

Example

  Copy Code
HRESULT SendDiscoveryRecord()
{
	ISmsMessaging			 *pMessaging = NULL;
	ISmsMessage				 *pMessage = NULL;
	WCHAR					 *pszDDRHeader = NULL;
	WCHAR					 *pszDDRReport = NULL;
	WCHAR					 *pszTrackingID = NULL;
	DWORD					 dwReportLen = 0;

	_BEGIN

		// Create root messaging object.
		_CHECKHR( ::CoCreateInstance(
						CLSID_SmsMessaging,
						NULL,
						CLSCTX_INPROC,
						IID_ISmsMessaging,
						(LPVOID*)&pMessaging) );

		// Create message object for the DDR.
		_CHECKHR( pMessaging->CreateMessage(&pMessage) );

		// Set the target of the message to be the DDR endpoint.
		_CHECKHR( pMessage->SetTargetEndpoint(L"MP_DdrEndpoint") );

		// Construct a DDR message. A DDR consists of two pieces, the report
		// header and the report itself.
		_CHECKHR( CreateDDR(&pszDDRHeader, &pszDDRReport) );

		// Compute report length, in bytes. (note null
		// terminator is not included for attachments)
		dwReportLen = lstrlen(pszDDRReport)*sizeof(WCHAR);

		// The report header must be set on the message body, as a string.
		_CHECKHR( pMessage->SetBodyFromString(pszDDRHeader) );

		// The report itself must be set as a message attachment.  The name
		// of the attachment must be a GUID for DDR.
		_CHECKHR( pMessage->SetAttachmentFromBuffer(
						L"{00000000-0000-0000-0000-000000000003}", // DDR
						(const BYTE*)pszDDRReport,
						dwReportLen) );

		// Post the DDR message to the DDR Manager on the local computer.
		_CHECKHR( pMessaging->Post(NULL, pMessage, &pszTrackingID) );

		// Add code to track the message by using the tracking ID.

	_END

	// All cleanup must go after _END block to ensure it gets invoked.

	if(pszTrackingID)
	{
		::CoTaskMemFree(pszTrackingID);
}

	if(pszDDRReport)
	{
		::CoTaskMemFree(pszDDRReport);
}

	if(pszDDRHeader)
	{
		::CoTaskMemFree(pszDDRHeader);
}

	if(pMessage)
	{
		pMessage->Release();
}

	if(pMessaging)
	{
		pMessaging->Release();
}

	return _RETVAL;
}

Compiling the Code

Management Point Interfaces DLL.

Security

You can set security options for a message by using ISmsMessage4 Interface. For more information, see Configuration Manager Management Point Interface Security.

See Also


Send comments about this topic to Microsoft.