Adding a Schedule Using C++

The following is a C++ code fragment that adds a new schedule called "Extended Work Hours," which includes all hours on all days. This code was written as a Windows Console Application. To use this code:

  1. In Visual C++, create a new Win32 Console Application.
  2. Select the default empty project.
  3. Create a new C++ source file in the workspace.
  4. Paste the following code into the C++ source file, and build the project.
    //Import the Forefront TMG Msfpccom.dll file so that Forefront TMG COM objects can be used.
    //Use the path to your Forefront TMG installation directory, or search for Msfpccom.idl.
    #import "c:\Program Files\Microsoft ISA Server\msfpccom.dll"
    #include <iostream.h>
    int main ()
    {
    	try 
    	{ 
    		// Define variables.
    		HRESULT hr;
    		//Initialize the COM library on the current thread.
    		hr = CoInitialize( NULL ); 
    		{
    			// Define variables.
    			FPCLib::IFPCPtr sipRoot;
    			FPCLib::IFPCSchedulesPtr sipMyScheduleCol;
    			FPCLib::IFPCSchedulePtr sipMySchedule;
    			// Create the Forefront TMG root object.
    			hr = sipRoot.CreateInstance("FPC.Root");
    			//Retrieve the schedules collection.
    			sipMyScheduleCol = sipRoot->GetContainingArray()->RuleElements->Schedules;
    			//Add the new schedule.
    			sipMySchedule = sipMyScheduleCol->Add("Extended Work Hours");
    			//Set the schedule.
    			sipMySchedule->Set(FPCLib::fpcALL_WEEK, FPCLib::fpcALL_DAY);
    			//Save your changes.
    			sipMyScheduleCol->Save();
    	}
    }
    	catch (_com_error& e) 
    	{
    		cout << 
    			"Error. HRESULT message is: \"" <<
    			e.ErrorMessage() <<
    			"\" (" << 
    			e.Error() << 
    			")" << 
    			endl; 
    		if (e.ErrorInfo()) 
    		{ 
    			cout << (char *)e.Description() << endl; 
    	} 
    } 
    		CoUninitialize();
    		return 0;
    }
    
  5. Run the application.

See Also

FPCSchedule
Modify a Schedule


Send comments about this topic to Microsoft

Build date: 11/30/2009

© 2008 Microsoft Corporation. All rights reserved.