Article ID: 183920
Article Last Modified on 7/1/2004
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <winbase.h>
/* Generate an MTS-ID value for tracking inbound messages,
and to correctly route Non-Delivery Reports. */
#define MAX_LENGTH_MTS_ID 255
void main( )
{
/* A pocket for the generated MTS_ID value. */
LPSTR lpszMTSID;
/* Character buffer for munching on the X400 ID. */
CHAR buf1[MAX_LENGTH_MTS_ID];
/* An X400 ID from any recipient. */
LPSTR lpszX400Adr = NULL;
/* String pointer. */
LPSTR p = NULL;
/* The name of the computer running this code. */
CHAR szComputerName[MAX_COMPUTERNAME_LENGTH+1];
/* Defined in Winbase.h */
DWORD dwCompNameBufferSize = MAX_COMPUTERNAME_LENGTH;
/* Obtain the system time. Assists to make this value unique. */
SYSTEMTIME sysTime;
GetSystemTime( &sysTime );
/* Supply a valid X400 address to use in the MTS_ID value.
For example, the gateway administrator's X400 proxy. */
lpszX400Adr = "c=US;a= ;p=FooSite;s=TomBoy;";
/* Set the first character in the buffer to NULL */
buf1[0] = '\0';
/* Find the first semicolon in the X400 Address.
The semicolon is the element separator in the address type. */
p = strtok(lpszX400Adr, ";")
/* As long as there is an element at p, check to see if the
character is 'c' or 'a' or 'p', AND the next character is an
'='. If so, we have an element of the X400 address. */
while (p)
{
if (('c'== *p || 'a'== *p || 'p' == *p) && '=' == *(p+1))
{
/* Put it in the buffer, and add a semicolon. */
strcat(buf1, p);
strcat(buf1, ";");
}
/* Find the next element in the X400 address. */
p = strtok(NULL, ";");
}
/* The next component of the PR_MTS_ID value is the name of the
computer running this program. For now, assume that this call
always works. For more information on GetComputerName, look
under "Setup and Systems Management Services" in the
Platform SDK. */
GetComputerName(szComputerName, &dwCompNameBufferSize);
/* GetComputerName does not null-terminate the returned string,
so we do it. */
szComputerName[MAX_COMPUTERNAME_LENGTH] = '\0';
/* Copy the whole mess into a string. */
sprintf(lpszMTSID,
"%sl=%s%02d%02d%02d%02d%02d%02d%04d", buf1, szComputerName,
sysTime.wYear % 100, sysTime.wMonth, sysTime.wDay, sysTime.wHour,
sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds);
/* Tell the world. */
printf("The MTS_ID value is %s\n", lpszMTSID);
return;
}
Keywords: kbhowto KB183920