C/C++ Example
The following is a C/C++ example.
/***********************************************************************
* *
* psportal_test.cpp *
* *
************************************************************************
* *
* Confidentiality Information: *
* *
* This module is the confidential and proprietary information of
* PeopleSoft, Inc.; it is not to be copied, reproduced, or
* transmitted in any form, by any means, in whole or in part,
* nor is it to be used for any purpose other than that for which it
* is expressly provided without the written
* permission of PeopleSoft.
* *
* Copyright (c) 1988-1999 PeopleSoft, Inc. All Rights Reserved. *
* *
************************************************************************
* *
* SourceSafe Information: *
* *
* $Logfile:: $*
* $Revision:: $*
* $Date:: $*
* *
***********************************************************************/
/***********************************************************************
* includes *
***********************************************************************/
#ifdef PS_WIN32
#include "stdafx.h"
#endif
#include "bcdef.h"
#include "apiadapterdef.h"
#include "peoplesoft_peoplesoft_i.h"
#include <stdio.h>
#include <iostream.h>
#include <wchar.h>
/***********************************************************************
* general defines and macros *
***********************************************************************/
/***********************************************************************
* globals *
***********************************************************************/
HPSAPI_SESSION hSession;
/***********************************************************************
* function prototypes *
***********************************************************************/
void DisconnectSession();
void GetFolder(HPSAPI_SESSION hSession, LPTSTR pszPortalName);
void OutError(HPSAPI_SESSION hSession);
/***********************************************************************
* Function: main *
* *
* Description: *
* *
* Returns: *
***********************************************************************/
void main(int argc, char* argv[])
{
// Declare variables
PSAPIVARBLOB blobExtra;
TCHAR szServer[80] = _T("//LCHE0110:900");
TCHAR szUserid[30] = _T("PTMO");
TCHAR szUserPswd[80] = _T("PT");
TCHAR szPortalName[80] = _T("PORTAL");
memset(&blobExtra, 0, sizeof(PSAPIVARBLOB));
// Establish a PeopleSoft Session.
HPSAPI_SESSION hSession = PeopleSoft_Session_Create();
if (PeopleSoft_Session_Connect(hSession, 1, szServer, szUserid, szUserPswd,⇒
blobExtra))
{
GetFolder(hSession, szPortalName);
}
else
{
// Connect to AppServer Failed. Error out.
if (PeopleSoft_Session_GetErrorPending(hSession))
{
wprintf(L"\nConnect to AppServer Failed.\n");
OutError(hSession);
}
else
wprintf(L"No error pending from session.\n");
}
DisconnectSession();
}
/***********************************************************************
* function implementations *
***********************************************************************/
/***********************************************************************
* Function: DisconnectSession *
* *
* Description: Disconnects the Session object. *
* *
* Returns: None *
***********************************************************************/
void DisconnectSession()
{
// Disconnect current session to free memory and session variables.
if (hSession)
{
if (PeopleSoft_Session_Disconnect(hSession))
{
PeopleSoft_Session_Release(hSession);
}
else
{
wprintf(L"Disconnect to AppServer Failed.\n");
}
}
}
/***********************************************************************
* Function: GetFolder *
* *
* Description: Get root folder and display folder name *
* *
* Returns: None *
***********************************************************************/
void GetFolder(HPSAPI_SESSION hSession, LPTSTR pszPortalName)
{
LPTSTR szStr;
HPSAPI_PORTALREGISTRY hPortal;
HPSAPI_FOLDER hRootFolder;
hPortal=(HPSAPI_PORTALREGISTRY) PeopleSoft_Session_GetPortalRegistry(hSession);
PortalRegistry_PortalRegistry_Open(hPortal, pszPortalName);
if (PortalRegistry_PortalRegistry_Open(hPortal, pszPortalName) == false)
_tprintf(_T("Open portal failed\n"));
else
{
hRootFolder = PortalRegistry_PortalRegistry_GetRootFolder(hPortal);
szStr = PortalRegistry_Folder_GetName(hRootFolder);
_tprintf(_T("root folder name = %s\n"), szStr);
}
}
/***********************************************************************
* Function: OutError *
* *
* Description: Output error message from session psMessage object *
* *
* Returns: None *
***********************************************************************/
void OutError(HPSAPI_SESSION hSession)
{
LPTSTR szStr;
HPSAPI_PSMESSAGECOLLECTION hMsgColl;
HPSAPI_PSMESSAGE hMsg;
hMsgColl=(HPSAPI_PSMESSAGECOLLECTION) PeopleSoft_Session_GetPSMessages(h⇒
Session);
wprintf(L"Get psMessage collection ok.\n");
int i;
PSI32 count;
count=(PSI32) PeopleSoft_PSMessageCollection_GetCount;
wprintf(L"Count= %d\n", count);
for (i=0; i<count; i++)
{
hMsg=(HPSAPI_PSMESSAGE) PeopleSoft_PSMessageCollection_Item(hMsgColl, i);
szStr=PeopleSoft_PSMessage_GetText(hMsg);
wprintf(L"\nMessage from session: %s\n",szStr);
}
}