Introduction to the SMS 2003 Management Point (MP) API

The MP API was introduced in the second release of the SMS SDK (we are currently in the fourth release, version 3.1).  This API is very powerful and can be used to submit discovery, inventory, status, and metering data from a SMS or non-SMS client.  It can also be used to request information from an MP, like policies or the location of a distribution point based on an IP subnet or AD site. 

This example shows how to submit a location request to an MP via the MP API.  This can be useful for a non-SMS client to be able to find out where to install an SMS package from.  A common scenario would be a new install of the OS (maybe right after an image is applied).  You could use the MP API to find out where to install the software needed on the image in order to get the machine up to a baseline.  I created a win32 console application in Visual Studio and checked the box to add MFC support.  For this application to work the smsmsgapi.dll must be registered on the machine (regsvr32 smsmsgapi.dll).  Also, make sure smsmsgapi.h and smsmsgapi_i.c are in your project folder.  All of these files are included in the SMS SDK.


// LocationRequest.cpp : Defines the entry point for the console application.
// Example of how to submit a location request using the MP API

#include "stdafx.h"
#include "LocationRequest.h"
#include "SmsMsgAPI.h"
#include "SmsMsgAPI_i.c"
#ifdef _DEBUG
#define new DEBUG_NEW

CWinApp theApp;

using namespace std;

// Macros to perform error handling and make the code cleaner.
#define _BEGIN \
HRESULT __hrRetVal = S_OK; \
{ \

#define _END \
} \
__End: \

#define _RETVAL __hrRetVal

#define _CHECKHR(expr) if(FAILED(expr)) { __hrRetVal=expr; goto __End; }

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
int nRetCode = 0;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
if(argc < 4)
printf("Usage:LocationRequest.exe <http://mpname> <CliSubnet> <CliIP> <PkgID> <ADSite>\n");
CString sMPIP, sClientSubnet, sClientIP, sPackageID, sADSite;
ISmsMessaging *pMessaging = NULL;
ISmsMessage *pRequest = NULL;
ISmsMessage *pReply = NULL;
WCHAR *pszRequestMessage = NULL;
WCHAR *pszReplyMessage = NULL;
CString sNewLocationRequest;
BSTR sLocationRequest = NULL;
BSTR sMPIPAddress;

//Get command line arguments
sMPIP = argv[1];
sClientSubnet = argv[2];
sClientIP = argv[3];
sPackageID = argv[4];
sADSite = argv[5];

//Format XML based Location Request
sNewLocationRequest =
"<ContentLocationRequest SchemaVersion=\"1.0\"> \n \
<Package ID=\""
+ sPackageID +
"\" Version=\"*\"/> \n \
<AssignedSite SiteCode=\"*\"/> \n \
<ClientLocationInfo> \n \
<ADSite Name=\""
+ sADSite +
"\"/> \n \
<IPAddresses> \n \
<IPAddress SubnetAddress=\""
+ sClientSubnet + "\" Address=\"" + sClientIP +
"\"/> \n \
</IPAddresses> \n \
</ClientLocationInfo> \n \

printf("\nLocation Request:\n%s",sNewLocationRequest); //Print request to command line

sLocationRequest = sNewLocationRequest.AllocSysString();
sMPIPAddress = sMPIP.AllocSysString();


//Create root messaging object
_CHECKHR( ::CoCreateInstance(
(LPVOID*)&pMessaging) );

//Create message object for request
_CHECKHR( pMessaging->CreateMessage(&pRequest) );

//Set the target of the message to the Location Manager endpoint
_CHECKHR( pRequest->SetTargetEndpoint(L"MP_LocationManager") );

//Set the message body with the request
_CHECKHR( pRequest->SetBodyFromString(sLocationRequest) );

// Invoke the targeted endpoint on the local machine with the request,
// and retrieve the reply.

_CHECKHR( pMessaging->Invoke(sMPIPAddress, pRequest, &pReply) );

// Extract body from reply message.
_CHECKHR( pReply->GetBodyToString(&pszReplyMessage) );

wprintf(L"\n\nReply from MP:\n%s", (wchar_t *) pszReplyMessage);


printf("\n\n%s%X", "Return Code=", __hrRetVal);

return nRetCode;

Comments (12)

  1. qmingz says:

    Where can I find smsmsgapi.dll? I installed the SMS2003, with SP1, but still can not find that dll available on the hard disk

  2. Russ Slaten says:

    It’s in the SDK:

    I’ll be posting more examples on using the MP API in June.  I’m waiting on an update to some of the files in the SDK which are needed in order to use the MP API to submit data (although the Location Request works fine with the current SDK).

  3. qmingz says:

    That is the SDK installed on my system, but I can not find the dll file in my SDK installation at all. Would you please tell me where should be this dll installed after SDK installation? Thanks.

  4. Russ Slaten says:

    Under the SDK directoryRedistributablesSMSMPAPI there is an mpapi.msi file.  Install this, then the dll should be located under the c:SMS_SDK directory.  This files to add to your project are under SamplesOtherSMSMPAPI.

    – Russ

  5. qmingz says:

    Thank you. Got it!

  6. gdeckler says:

    I can’t get this to compile under Visual Studio 2005. I get link errors.

    I created a new C++ project and checked MFC, left everything else defaults. Pasted in the code and had to change how the message string was concatenated together (used .Append versus +). Any help is greatly appreciated.

    —— Build started: Project: LocationRequest, Configuration: Debug Win32 ——


    smsmsgapi_i.obj : error LNK2005: _IID_ISmsMessaging already defined in LocationRequest.obj

    smsmsgapi_i.obj : error LNK2005: _IID_ISmsMessage already defined in LocationRequest.obj

    smsmsgapi_i.obj : error LNK2005: _IID_ISmsMessageAttachment already defined in LocationRequest.obj

    smsmsgapi_i.obj : error LNK2005: _LIBID_SmsMsgAPI already defined in LocationRequest.obj

    smsmsgapi_i.obj : error LNK2005: _CLSID_SmsMessaging already defined in LocationRequest.obj

    C:DataCodeProjectsLocationRequestDebugLocationRequest.exe : fatal error LNK1169: one or more multiply defined symbols found

    Build log was saved at "file://c:DataCodeProjectsLocationRequestLocationRequestDebugBuildLog.htm"

    LocationRequest – 6 error(s), 0 warning(s)

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  7. Russ Slaten says:

    I haven’t compiled in this quite some time and I think the last time I did it I used Visual Studio 2003.  I’ll try and do this in 2005 early next week and comment on my results…

  8. gdeckler says:

    I got it to compile in VS2005 by taking out the include for the SmsMsgAPI.c. Apparently since it was in my project and in the code as an include, it was including the same code twice. Also had to get rid of the use of "+" for appending. Pain.

    Where I am right now is that I send my soap request to the MP and I get a response back. The response however is just:

    <ContentLocationReply SchemaVersion="1.00"><Sites/></ContentLocationReply>

    Return Code=0

    I’m not sure what I should be seeing, but I would have thought there would have been a distribution point path or server name or something in there. Still working away on this one but figured I’d give you an update. I am going back to the API’s to see if they provide any additional guidance.

  9. Russ Slaten says:

    You should be seeing more than that (you’ll get a DP name) unless you didn’t pass the right information like AD site, subnet, etc…  You can see what the advanced client gets back by running an advert from it while verbose/debug logging is enabled on the MP.  The format will look exactly like the XML you get back from the MP API.

  10. gdeckler says:

    This is what I am sending, after reading the SMS API, it indicated to use "LocalMPLocationRequest" to get the DP. But, I would get the same information either way (ContentLocationRequest) which tells me I am probably doing something wrong or have something formatted incorrectly…

    <LocalMPLocationRequest SchemaVersion="1.00">

     <AssignedSite SiteCode="SMS:LC1"/>


       <ADSite Name="Backoffice_Primary"/>


         <IPAddress SubnetAddress="" Address=""/>




    This generates:

    <LocalMPLocationReply SchemaVersion="1.00"><Sites/></LocalMPLocationReply>

    Return Code = 0

    Any assistance is greatly appreciated, this is driving me crazy. The values for Subnet, IP address, AD site, etc. are coming from the SMS Advanced Client properties via code such as:


    set objCPAppletMgr=CreatObject("CPApplet.CPAppletMgr")

    set objClientProperties=objCPAppletMgr.GetClientProperties

    set objClientProperty=objClientProperties(3)


  11. gdeckler says:

    OK, I got it fixed, the problem was that the SMS Administrators had done some funky things with the boundaries and there was no distribution point for the workstation. Everything is working now. Thanks!

  12. permster says:

    Anyone know how you can get this API working if you don’t have domain authentication?  For example, if your logged in as local administrator?  Is there a way to pass authentication?

    When I run it in Windows as a domain user everything works fine, but when I run it as local administrator I get return code 80072F78.

Skip to main content