Platform SDK: Team Productivity Update

Gathering Command-Line Parameters

The program for registering an application with the Team Productivity Update begins with the following preprocessor directives and the declaration of an array for storing the GUIDs of registered applications. Next, the code includes a macro for checking the return values from the calls to TeamAppManager.

#include <stdio.h>
#include <string.h>
#include <objbase.h>
#include <atlbase.h>
#include <comdef.h>

#import "tptk.tlb" no_namespace named_guids raw_interfaces_only //raw_dispinterfaces

#define MY_MAXSTRLEN 256
#define MY_MAXNUBOFID 32

CComBSTR bstrRegisteredIDs[MY_MAXNUBOFID]; // array for storing registered IDs
int     IDindex = 0;               // points to the next empty entry

// simple macro to check the return code
#define SHOWRET(hr, mesg) if ( FAILED(hr)) { printf("error: %s failed, return value 0x%X\n", mesg, hr); return -1; } else printf("%s succeeded, return value 0x%X\n", mesg, hr);

The following function, GetArguments(), is called to gather parameters from the command line and stores them for later use by the calls to the TeamAppManager object. The function is called from case "r" inside the SWITCH block used to control which TeamAppManager method is invoked.

// function for getting the arguments from the user
void GetArguments(LPSTR lpzrInstantiateURL, LPSTR lpzrFriendlyName, LPSTR lpzrDescription, TeamAppFactoryType *AppFactoryTypePtr)
{
  fflush(stdin);
  printf("input the instantiation URL : ");
  gets(lpzrInstantiateURL);

  printf("input the friendly name : ");
  gets(lpzrFriendlyName);

  printf("input the description : ");
  gets(lpzrDescription);

  char strAppFactoryType[MY_MAXSTRLEN];
  printf("input the instantiation URL type -- LINK|DEPLOY|CONFIG : "); 
  gets(strAppFactoryType);
  if ( strncmp(strAppFactoryType, "LINK", 4) == 0)
    *AppFactoryTypePtr = TAFT_LINK;
  else if ( strncmp(strAppFactoryType, "DEPLOY", 6) == 0)
    *AppFactoryTypePtr = TAFT_DEPLOY;
  else if (strncmp(strAppFactoryType, "CONFIG", 6) == 0)
    *AppFactoryTypePtr = TAFT_FACTORY;
  else {
    puts("invalid type");
    exit(-1);
  }
}

// display all registered IDs in the array
void ShowGUIDs(void) 
{
  USES_CONVERSION;
  LPCSTR lpzrUniqueIdentifier = NULL;  

  puts("\nRegistered IDs:");
  for ( int i = 0; i < IDindex; i++) {
    // convert the factory ID to string
    lpzrUniqueIdentifier = OLE2A(bstrRegisteredIDs[i]);
    printf("AppFactoryID: %s\n", lpzrUniqueIdentifier);
  }