Platform SDK: Team Productivity Update

TeamAppManager Method Calls

The following code presents the user with options to call one of the three methods for adding an application to the Team Productivity Update Team Workspace. The function uses a SWITCH statement to call each of the three TeamAppManager functions, based on user input. Selecting case "r" for the RegisterAppFactory method calls to a function, GetArguments(), which prompts the user for command-line parameters used by the RegisterAppFactory method.

// the main function
int __cdecl main(int argc, char *argv[])
{
  HRESULT hr;

  puts("");
  hr = CoInitialize(NULL);
  SHOWRET(hr, "CoInitialize");

  // initialize the TeamAppManager
  CComPtr<ITeamAppManager> pTeamAppManager;
  hr = pTeamAppManager.CoCreateInstance(CLSID_TeamAppManager);
  SHOWRET(hr, "CoCreateInstance");
  ATLASSERT(pTeamAppManager);

  static char InstantiateURL[MY_MAXSTRLEN];    // the instantiation URL
  static char FriendlyName [MY_MAXSTRLEN];    // the friendly name for the App
  static char Description[MY_MAXSTRLEN];    // the description for the App
  TeamAppFactoryType AppFactoryType = TAFT_LINK;    // set default to LINK

  CComBSTR bstrFriendlyName;        // return value from FriendlyNameFromGUID
  CComBSTR bstrUniqueIdentifier;    // return value from RegisterAppFactory
  LPCSTR lpzrFriendlyName = NULL;

  USES_CONVERSION;
  char c;
  do {
    puts("\nChoose: r--Register u--Unregister f--FriendlyNameFromGUID q--Quit");
    fflush(stdin);

    switch ( (c = getchar())) {
    case 'r':
      // prompt for input
      GetArguments(InstantiateURL, FriendlyName, Description, &AppFactoryType);
      // register the application factory
      printf("registering application factory ... ");
      hr = pTeamAppManager->RegisterAppFactory(CComBSTR(InstantiateURL),
                           AppFactoryType,
                           CComBSTR(FriendlyName),
                           NULL,    // pointer to icon
                           CComBSTR(Description),
                           &bstrUniqueIdentifier);
      SHOWRET(hr, "RegisterAppFactory");      
      bstrRegisteredIDs[IDindex++] = bstrUniqueIdentifier;    // save the ID
      ShowGUIDs();
      break;

    case 'u':
      printf("unregistering the most recently registered factory ... ");
      hr = pTeamAppManager->UnregisterAppFactory(bstrRegisteredIDs[IDindex-1]);
      SHOWRET(hr, "UnregisterAppFactory");
      bstrRegisteredIDs[IDindex--].Empty();    // remove the ID from the array
      puts("last entry unregistered");
      ShowGUIDs();
      break;

    case 'f':
      printf("Getting the friendly name from GUID ... ");
      hr = pTeamAppManager->FriendlyNameFromGUID(bstrRegisteredIDs[IDindex-1],
                         &bstrFriendlyName);
      SHOWRET(hr, "FriendlyNameFromGUID");
      lpzrFriendlyName = OLE2A(bstrFriendlyName);
      printf("Friendly name for the last entry is: %s\n",
         lpzrFriendlyName);
      break;

    case 'q':
      break;

    default:
      puts("Invalid option, choose again");
      break;
    }
  } while ( c != 'q');

  // release the TeamAppManager
  pTeamAppManager.Release();

  CoUninitialize();
  return 0;
}